libbb: introduce bb_signals and bb_signals_recursive,
which sets same handler for many signals. sig_catch is nuked (bb_signals_recursive is more descriptive name). *: use them as appropriate. function old new delta bb_signals_recursive - 95 +95 bb_signals - 52 +52 run_command 258 273 +15 svlogd_main 1368 1377 +9 runsv_main 1746 1752 +6 runsvdir_main 1643 1646 +3 UNSPEC_print 64 66 +2 time_main 1128 1127 -1 ... resize_main 246 210 -36 sig_catch 63 - -63 set_fatal_sighandler 85 14 -71 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 5/24 up/down: 182/-548) Total: -366 bytes
This commit is contained in:
parent
7fc294cdfe
commit
25591c322c
@ -37,10 +37,12 @@ int resize_main(int argc, char **argv)
|
|||||||
new = old_termios;
|
new = old_termios;
|
||||||
new.c_cflag |= (CLOCAL | CREAD);
|
new.c_cflag |= (CLOCAL | CREAD);
|
||||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||||
signal(SIGINT, onintr);
|
bb_signals(0
|
||||||
signal(SIGQUIT, onintr);
|
+ (1 << SIGINT)
|
||||||
signal(SIGTERM, onintr);
|
+ (1 << SIGQUIT)
|
||||||
signal(SIGALRM, onintr);
|
+ (1 << SIGTERM)
|
||||||
|
+ (1 << SIGALRM)
|
||||||
|
, onintr);
|
||||||
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
||||||
|
|
||||||
/* save_cursor_pos 7
|
/* save_cursor_pos 7
|
||||||
|
@ -36,12 +36,12 @@ int tee_main(int argc, char **argv)
|
|||||||
mode += (retval & 2); /* Since 'a' is the 2nd option... */
|
mode += (retval & 2); /* Since 'a' is the 2nd option... */
|
||||||
|
|
||||||
if (retval & 1) {
|
if (retval & 1) {
|
||||||
signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. */
|
signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */
|
||||||
}
|
}
|
||||||
retval = EXIT_SUCCESS;
|
retval = EXIT_SUCCESS;
|
||||||
/* gnu tee ignores SIGPIPE in case one of the output files is a pipe
|
/* gnu tee ignores SIGPIPE in case one of the output files is a pipe
|
||||||
* that doesn't consume all its input. Good idea... */
|
* that doesn't consume all its input. Good idea... */
|
||||||
signal(SIGPIPE, SIG_IGN); /* TODO - switch to sigaction. */
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
/* Allocate an array of FILE *'s, with one extra for a sentinal. */
|
/* Allocate an array of FILE *'s, with one extra for a sentinal. */
|
||||||
fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
|
fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
|
||||||
|
@ -274,14 +274,18 @@ char *xrealloc_getcwd_or_warn(char *cwd);
|
|||||||
|
|
||||||
char *xmalloc_follow_symlinks(const char *path);
|
char *xmalloc_follow_symlinks(const char *path);
|
||||||
|
|
||||||
//TODO: signal(sid, f) is the same? then why?
|
//enum {
|
||||||
extern void sig_catch(int,void (*)(int));
|
// BB_SIGS_FATAL = ,
|
||||||
//#define sig_ignore(s) (sig_catch((s), SIG_IGN))
|
//};
|
||||||
//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
|
void bb_signals(int sigs, void (*f)(int));
|
||||||
extern void sig_block(int);
|
/* Unlike signal() and bb_signals, sets handler with sigaction()
|
||||||
extern void sig_unblock(int);
|
* and in a way that while signal handler is run, no other signals
|
||||||
/* UNUSED: extern void sig_blocknone(void); */
|
* will be blocked: */
|
||||||
extern void sig_pause(void);
|
void bb_signals_recursive(int sigs, void (*f)(int));
|
||||||
|
void sig_block(int);
|
||||||
|
void sig_unblock(int);
|
||||||
|
/* UNUSED: void sig_blocknone(void); */
|
||||||
|
void sig_pause(void);
|
||||||
|
|
||||||
|
|
||||||
void xsetgid(gid_t gid);
|
void xsetgid(gid_t gid);
|
||||||
|
48
init/init.c
48
init/init.c
@ -319,15 +319,17 @@ static pid_t run(const struct init_action *a)
|
|||||||
/* Child */
|
/* Child */
|
||||||
|
|
||||||
/* Reset signal handlers that were set by the parent process */
|
/* Reset signal handlers that were set by the parent process */
|
||||||
signal(SIGUSR1, SIG_DFL);
|
bb_signals(0
|
||||||
signal(SIGUSR2, SIG_DFL);
|
+ (1 << SIGUSR1)
|
||||||
signal(SIGINT, SIG_DFL);
|
+ (1 << SIGUSR2)
|
||||||
signal(SIGTERM, SIG_DFL);
|
+ (1 << SIGINT)
|
||||||
signal(SIGHUP, SIG_DFL);
|
+ (1 << SIGTERM)
|
||||||
signal(SIGQUIT, SIG_DFL);
|
+ (1 << SIGHUP)
|
||||||
signal(SIGCONT, SIG_DFL);
|
+ (1 << SIGQUIT)
|
||||||
signal(SIGSTOP, SIG_DFL);
|
+ (1 << SIGCONT)
|
||||||
signal(SIGTSTP, SIG_DFL);
|
+ (1 << SIGSTOP)
|
||||||
|
+ (1 << SIGTSTP)
|
||||||
|
, SIG_DFL);
|
||||||
|
|
||||||
/* Create a new session and make ourself the process
|
/* Create a new session and make ourself the process
|
||||||
* group leader */
|
* group leader */
|
||||||
@ -349,9 +351,11 @@ static pid_t run(const struct init_action *a)
|
|||||||
|
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
/* Parent - wait till the child is done */
|
/* Parent - wait till the child is done */
|
||||||
signal(SIGINT, SIG_IGN);
|
bb_signals(0
|
||||||
signal(SIGTSTP, SIG_IGN);
|
+ (1 << SIGINT)
|
||||||
signal(SIGQUIT, SIG_IGN);
|
+ (1 << SIGTSTP)
|
||||||
|
+ (1 << SIGQUIT)
|
||||||
|
, SIG_IGN);
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
|
|
||||||
waitfor(pid);
|
waitfor(pid);
|
||||||
@ -864,15 +868,21 @@ int init_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
/* Set up sig handlers -- be sure to
|
/* Set up sig handlers -- be sure to
|
||||||
* clear all of these in run() */
|
* clear all of these in run() */
|
||||||
signal(SIGHUP, exec_restart_action);
|
bb_signals(0
|
||||||
signal(SIGQUIT, exec_restart_action);
|
+ (1 << SIGHUP)
|
||||||
signal(SIGUSR1, halt_reboot_pwoff); /* halt */
|
+ (1 << SIGQUIT)
|
||||||
signal(SIGUSR2, halt_reboot_pwoff); /* poweroff */
|
, exec_restart_action);
|
||||||
signal(SIGTERM, halt_reboot_pwoff); /* reboot */
|
bb_signals(0
|
||||||
|
+ (1 << SIGUSR1) /* halt */
|
||||||
|
+ (1 << SIGUSR2) /* poweroff */
|
||||||
|
+ (1 << SIGTERM) /* reboot */
|
||||||
|
, halt_reboot_pwoff);
|
||||||
signal(SIGINT, ctrlaltdel_signal);
|
signal(SIGINT, ctrlaltdel_signal);
|
||||||
signal(SIGCONT, cont_handler);
|
signal(SIGCONT, cont_handler);
|
||||||
signal(SIGSTOP, stop_handler);
|
bb_signals(0
|
||||||
signal(SIGTSTP, stop_handler);
|
+ (1 << SIGSTOP)
|
||||||
|
+ (1 << SIGTSTP)
|
||||||
|
, stop_handler);
|
||||||
|
|
||||||
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
||||||
* SIGINT on CAD so we can shut things down gracefully... */
|
* SIGINT on CAD so we can shut things down gracefully... */
|
||||||
|
@ -78,6 +78,7 @@ lib-y += safe_strncpy.o
|
|||||||
lib-y += safe_write.o
|
lib-y += safe_write.o
|
||||||
lib-y += setup_environment.o
|
lib-y += setup_environment.o
|
||||||
lib-y += sha1.o
|
lib-y += sha1.o
|
||||||
|
lib-y += signals.o
|
||||||
lib-y += simplify_path.o
|
lib-y += simplify_path.o
|
||||||
lib-y += skip_whitespace.o
|
lib-y += skip_whitespace.o
|
||||||
lib-y += speed_table.o
|
lib-y += speed_table.o
|
||||||
|
80
libbb/signals.c
Normal file
80
libbb/signals.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
|
/*
|
||||||
|
* Utility routines.
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||||
|
* Copyright (C) 2006 Rob Landley
|
||||||
|
* Copyright (C) 2006 Denis Vlasenko
|
||||||
|
*
|
||||||
|
* Licensed under GPL version 2, see file LICENSE in this tarball for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libbb.h"
|
||||||
|
|
||||||
|
void bb_signals(int sigs, void (*f)(int))
|
||||||
|
{
|
||||||
|
int sig_no = 0;
|
||||||
|
int bit = 1;
|
||||||
|
|
||||||
|
while (sigs) {
|
||||||
|
if (sigs & bit) {
|
||||||
|
sigs &= ~bit;
|
||||||
|
signal(sig_no, f);
|
||||||
|
}
|
||||||
|
sig_no++;
|
||||||
|
bit <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void bb_signals_recursive(int sigs, void (*f)(int))
|
||||||
|
{
|
||||||
|
int sig_no = 0;
|
||||||
|
int bit = 1;
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
sa.sa_handler = f;
|
||||||
|
/*sa.sa_flags = 0;*/
|
||||||
|
/*sigemptyset(&sa.sa_mask); - hope memset did it*/
|
||||||
|
|
||||||
|
while (sigs) {
|
||||||
|
if (sigs & bit) {
|
||||||
|
sigs &= ~bit;
|
||||||
|
sigaction(sig_no, &sa, NULL);
|
||||||
|
}
|
||||||
|
sig_no++;
|
||||||
|
bit <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_block(int sig)
|
||||||
|
{
|
||||||
|
sigset_t ss;
|
||||||
|
sigemptyset(&ss);
|
||||||
|
sigaddset(&ss, sig);
|
||||||
|
sigprocmask(SIG_BLOCK, &ss, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_unblock(int sig)
|
||||||
|
{
|
||||||
|
sigset_t ss;
|
||||||
|
sigemptyset(&ss);
|
||||||
|
sigaddset(&ss, sig);
|
||||||
|
sigprocmask(SIG_UNBLOCK, &ss, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void sig_blocknone(void)
|
||||||
|
{
|
||||||
|
sigset_t ss;
|
||||||
|
sigemptyset(&ss);
|
||||||
|
sigprocmask(SIG_SETMASK, &ss, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sig_pause(void)
|
||||||
|
{
|
||||||
|
sigset_t ss;
|
||||||
|
sigemptyset(&ss);
|
||||||
|
sigsuspend(&ss);
|
||||||
|
}
|
@ -234,48 +234,6 @@ void xfflush_stdout(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sig_block(int sig)
|
|
||||||
{
|
|
||||||
sigset_t ss;
|
|
||||||
sigemptyset(&ss);
|
|
||||||
sigaddset(&ss, sig);
|
|
||||||
sigprocmask(SIG_BLOCK, &ss, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sig_unblock(int sig)
|
|
||||||
{
|
|
||||||
sigset_t ss;
|
|
||||||
sigemptyset(&ss);
|
|
||||||
sigaddset(&ss, sig);
|
|
||||||
sigprocmask(SIG_UNBLOCK, &ss, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
void sig_blocknone(void)
|
|
||||||
{
|
|
||||||
sigset_t ss;
|
|
||||||
sigemptyset(&ss);
|
|
||||||
sigprocmask(SIG_SETMASK, &ss, NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void sig_catch(int sig, void (*f)(int))
|
|
||||||
{
|
|
||||||
struct sigaction sa;
|
|
||||||
sa.sa_handler = f;
|
|
||||||
sa.sa_flags = 0;
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
sigaction(sig, &sa, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sig_pause(void)
|
|
||||||
{
|
|
||||||
sigset_t ss;
|
|
||||||
sigemptyset(&ss);
|
|
||||||
sigsuspend(&ss);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xsetenv(const char *key, const char *value)
|
void xsetenv(const char *key, const char *value)
|
||||||
{
|
{
|
||||||
if (setenv(key, value, 1))
|
if (setenv(key, value, 1))
|
||||||
|
@ -171,9 +171,11 @@ int passwd_main(int argc, char **argv)
|
|||||||
|
|
||||||
rlimit_fsize.rlim_cur = rlimit_fsize.rlim_max = 512L * 30000;
|
rlimit_fsize.rlim_cur = rlimit_fsize.rlim_max = 512L * 30000;
|
||||||
setrlimit(RLIMIT_FSIZE, &rlimit_fsize);
|
setrlimit(RLIMIT_FSIZE, &rlimit_fsize);
|
||||||
signal(SIGHUP, SIG_IGN);
|
bb_signals(0
|
||||||
signal(SIGINT, SIG_IGN);
|
+ (1 << SIGHUP)
|
||||||
signal(SIGQUIT, SIG_IGN);
|
+ (1 << SIGINT)
|
||||||
|
+ (1 << SIGQUIT)
|
||||||
|
, SIG_IGN);
|
||||||
umask(077);
|
umask(077);
|
||||||
xsetuid(0);
|
xsetuid(0);
|
||||||
|
|
||||||
|
@ -1355,8 +1355,10 @@ int less_main(int argc, char **argv)
|
|||||||
empty_line_marker = "";
|
empty_line_marker = "";
|
||||||
|
|
||||||
tcgetattr(kbd_fd, &term_orig);
|
tcgetattr(kbd_fd, &term_orig);
|
||||||
signal(SIGTERM, sig_catcher);
|
bb_signals(0
|
||||||
signal(SIGINT, sig_catcher);
|
+ (1 << SIGTERM)
|
||||||
|
+ (1 << SIGINT)
|
||||||
|
, sig_catcher);
|
||||||
term_less = term_orig;
|
term_less = term_orig;
|
||||||
term_less.c_lflag &= ~(ICANON | ECHO);
|
term_less.c_lflag &= ~(ICANON | ECHO);
|
||||||
term_less.c_iflag &= ~(IXON | ICRNL);
|
term_less.c_iflag &= ~(IXON | ICRNL);
|
||||||
|
@ -99,10 +99,12 @@ int microcom_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup signals
|
// setup signals
|
||||||
sig_catch(SIGHUP, signal_handler);
|
bb_signals_recursive(0
|
||||||
sig_catch(SIGINT, signal_handler);
|
+ (1 << SIGHUP)
|
||||||
sig_catch(SIGTERM, signal_handler);
|
+ (1 << SIGINT)
|
||||||
sig_catch(SIGPIPE, signal_handler);
|
+ (1 << SIGTERM)
|
||||||
|
+ (1 << SIGPIPE)
|
||||||
|
, signal_handler);
|
||||||
|
|
||||||
// error exit code if we fail to open the device
|
// error exit code if we fail to open the device
|
||||||
signalled = 1;
|
signalled = 1;
|
||||||
|
@ -61,7 +61,7 @@ static const char long_format[] ALIGN1 =
|
|||||||
Return 0 on error, 1 if ok. */
|
Return 0 on error, 1 if ok. */
|
||||||
|
|
||||||
/* pid_t is short on BSDI, so don't try to promote it. */
|
/* pid_t is short on BSDI, so don't try to promote it. */
|
||||||
static int resuse_end(pid_t pid, resource_t * resp)
|
static int resuse_end(pid_t pid, resource_t *resp)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
pid_t caught;
|
pid_t caught;
|
||||||
@ -69,7 +69,7 @@ static int resuse_end(pid_t pid, resource_t * resp)
|
|||||||
/* Ignore signals, but don't ignore the children. When wait3
|
/* Ignore signals, but don't ignore the children. When wait3
|
||||||
returns the child process, set the time the command finished. */
|
returns the child process, set the time the command finished. */
|
||||||
while ((caught = wait3(&status, 0, &resp->ru)) != pid) {
|
while ((caught = wait3(&status, 0, &resp->ru)) != pid) {
|
||||||
if (caught == -1)
|
if (caught == -1 && errno != EINTR)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
resp->elapsed_ms = (monotonic_us() / 1000) - resp->elapsed_ms;
|
resp->elapsed_ms = (monotonic_us() / 1000) - resp->elapsed_ms;
|
||||||
@ -373,24 +373,26 @@ static void summarize(const char *fmt, char **command, resource_t * resp)
|
|||||||
|
|
||||||
/* Run command CMD and return statistics on it.
|
/* Run command CMD and return statistics on it.
|
||||||
Put the statistics in *RESP. */
|
Put the statistics in *RESP. */
|
||||||
static void run_command(char *const *cmd, resource_t * resp)
|
static void run_command(char *const *cmd, resource_t *resp)
|
||||||
{
|
{
|
||||||
pid_t pid; /* Pid of child. */
|
pid_t pid; /* Pid of child. */
|
||||||
__sighandler_t interrupt_signal, quit_signal;
|
void (*interrupt_signal)(int);
|
||||||
|
void (*quit_signal)(int);
|
||||||
|
|
||||||
resp->elapsed_ms = monotonic_us() / 1000;
|
resp->elapsed_ms = monotonic_us() / 1000;
|
||||||
pid = vfork(); /* Run CMD as child process. */
|
pid = vfork(); /* Run CMD as child process. */
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
bb_error_msg_and_die("cannot fork");
|
bb_error_msg_and_die("cannot fork");
|
||||||
else if (pid == 0) { /* If child. */
|
if (pid == 0) { /* If child. */
|
||||||
/* Don't cast execvp arguments; that causes errors on some systems,
|
/* Don't cast execvp arguments; that causes errors on some systems,
|
||||||
versus merely warnings if the cast is left off. */
|
versus merely warnings if the cast is left off. */
|
||||||
BB_EXECVP(cmd[0], cmd);
|
BB_EXECVP(cmd[0], cmd);
|
||||||
bb_error_msg("cannot run %s", cmd[0]);
|
xfunc_error_retval = (errno == ENOENT ? 127 : 126);
|
||||||
_exit(errno == ENOENT ? 127 : 126);
|
bb_error_msg_and_die("cannot run %s", cmd[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Have signals kill the child but not self (if possible). */
|
/* Have signals kill the child but not self (if possible). */
|
||||||
|
//TODO: just block all sigs? and reenable them in the very end in main?
|
||||||
interrupt_signal = signal(SIGINT, SIG_IGN);
|
interrupt_signal = signal(SIGINT, SIG_IGN);
|
||||||
quit_signal = signal(SIGQUIT, SIG_IGN);
|
quit_signal = signal(SIGQUIT, SIG_IGN);
|
||||||
|
|
||||||
|
@ -47,8 +47,10 @@ int watchdog_main(int argc, char **argv)
|
|||||||
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGHUP, watchdog_shutdown);
|
bb_signals(0
|
||||||
signal(SIGINT, watchdog_shutdown);
|
+ (1 << SIGHUP)
|
||||||
|
+ (1 << SIGINT)
|
||||||
|
, watchdog_shutdown);
|
||||||
|
|
||||||
/* Use known fd # - avoid needing global 'int fd' */
|
/* Use known fd # - avoid needing global 'int fd' */
|
||||||
xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
|
xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
|
||||||
|
@ -361,14 +361,16 @@ int dnsd_main(int argc, char **argv)
|
|||||||
dnsentryinit();
|
dnsentryinit();
|
||||||
|
|
||||||
signal(SIGINT, interrupt);
|
signal(SIGINT, interrupt);
|
||||||
/* why? signal(SIGPIPE, SIG_IGN); */
|
bb_signals(0
|
||||||
signal(SIGHUP, SIG_IGN);
|
/* why? + (1 << SIGPIPE) */
|
||||||
|
+ (1 << SIGHUP)
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
signal(SIGTSTP, SIG_IGN);
|
+ (1 << SIGTSTP)
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIGURG
|
#ifdef SIGURG
|
||||||
signal(SIGURG, SIG_IGN);
|
+ (1 << SIGURG)
|
||||||
#endif
|
#endif
|
||||||
|
, SIG_IGN);
|
||||||
|
|
||||||
lsa = xdotted2sockaddr(listen_interface, port);
|
lsa = xdotted2sockaddr(listen_interface, port);
|
||||||
udps = xsocket(lsa->u.sa.sa_family, SOCK_DGRAM, 0);
|
udps = xsocket(lsa->u.sa.sa_family, SOCK_DGRAM, 0);
|
||||||
|
@ -683,14 +683,18 @@ int nc_main(int argc, char **argv)
|
|||||||
PTR_TO_GLOBALS = xzalloc(sizeof(G));
|
PTR_TO_GLOBALS = xzalloc(sizeof(G));
|
||||||
|
|
||||||
/* catch a signal or two for cleanup */
|
/* catch a signal or two for cleanup */
|
||||||
signal(SIGINT, catch);
|
bb_signals(0
|
||||||
signal(SIGQUIT, catch);
|
+ (1 << SIGINT)
|
||||||
signal(SIGTERM, catch);
|
+ (1 << SIGQUIT)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, catch);
|
||||||
/* and suppress others... */
|
/* and suppress others... */
|
||||||
|
bb_signals(0
|
||||||
#ifdef SIGURG
|
#ifdef SIGURG
|
||||||
signal(SIGURG, SIG_IGN);
|
+ (1 << SIGURG)
|
||||||
#endif
|
#endif
|
||||||
signal(SIGPIPE, SIG_IGN); /* important! */
|
+ (1 << SIGPIPE) /* important! */
|
||||||
|
, SIG_IGN);
|
||||||
|
|
||||||
proggie = argv;
|
proggie = argv;
|
||||||
while (*++proggie) {
|
while (*++proggie) {
|
||||||
|
@ -111,8 +111,10 @@ static void launch_helper(const char **argv)
|
|||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
// parent - check whether child is alive
|
// parent - check whether child is alive
|
||||||
sig_catch(SIGCHLD, signal_handler);
|
bb_signals_recursive(0
|
||||||
sig_catch(SIGALRM, signal_handler);
|
+ (1 << SIGCHLD)
|
||||||
|
+ (1 << SIGALRM)
|
||||||
|
, signal_handler);
|
||||||
signal_handler(SIGCHLD);
|
signal_handler(SIGCHLD);
|
||||||
// child seems OK -> parent goes on
|
// child seems OK -> parent goes on
|
||||||
}
|
}
|
||||||
|
@ -175,10 +175,12 @@ int slattach_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Trap signals in order to restore tty states upon exit */
|
/* Trap signals in order to restore tty states upon exit */
|
||||||
if (!(opt & OPT_e_quit)) {
|
if (!(opt & OPT_e_quit)) {
|
||||||
signal(SIGHUP, sig_handler);
|
bb_signals(0
|
||||||
signal(SIGINT, sig_handler);
|
+ (1 << SIGHUP)
|
||||||
signal(SIGQUIT, sig_handler);
|
+ (1 << SIGINT)
|
||||||
signal(SIGTERM, sig_handler);
|
+ (1 << SIGQUIT)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, sig_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open tty */
|
/* Open tty */
|
||||||
|
@ -279,8 +279,7 @@ make_new_session(
|
|||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
/* Restore default signal handling */
|
/* Restore default signal handling */
|
||||||
signal(SIGCHLD, SIG_DFL);
|
bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
|
||||||
signal(SIGPIPE, SIG_DFL);
|
|
||||||
|
|
||||||
/* open the child's side of the tty. */
|
/* open the child's side of the tty. */
|
||||||
/* NB: setsid() disconnects from any previous ctty's. Therefore
|
/* NB: setsid() disconnects from any previous ctty's. Therefore
|
||||||
|
@ -42,9 +42,11 @@ void udhcp_sp_setup(void)
|
|||||||
close_on_exec_on(signal_pipe.rd);
|
close_on_exec_on(signal_pipe.rd);
|
||||||
close_on_exec_on(signal_pipe.wr);
|
close_on_exec_on(signal_pipe.wr);
|
||||||
ndelay_on(signal_pipe.wr);
|
ndelay_on(signal_pipe.wr);
|
||||||
signal(SIGUSR1, signal_handler);
|
bb_signals(0
|
||||||
signal(SIGUSR2, signal_handler);
|
+ (1 << SIGUSR1)
|
||||||
signal(SIGTERM, signal_handler);
|
+ (1 << SIGUSR2)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, signal_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -772,8 +772,10 @@ int top_main(int argc, char **argv)
|
|||||||
/* unbuffered input, turn off echo */
|
/* unbuffered input, turn off echo */
|
||||||
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
||||||
|
|
||||||
signal(SIGTERM, sig_catcher);
|
bb_signals(0
|
||||||
signal(SIGINT, sig_catcher);
|
+ (1 << SIGTERM)
|
||||||
|
+ (1 << SIGINT)
|
||||||
|
, sig_catcher);
|
||||||
tcsetattr(0, TCSANOW, (void *) &new_settings);
|
tcsetattr(0, TCSANOW, (void *) &new_settings);
|
||||||
atexit(reset_term);
|
atexit(reset_term);
|
||||||
#endif /* FEATURE_USE_TERMIOS */
|
#endif /* FEATURE_USE_TERMIOS */
|
||||||
|
@ -345,8 +345,10 @@ static void startservice(struct svdir *s)
|
|||||||
xdup2(logpipe.wr, 1);
|
xdup2(logpipe.wr, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signal(SIGCHLD, SIG_DFL);
|
bb_signals(0
|
||||||
signal(SIGTERM, SIG_DFL);
|
+ (1 << SIGCHLD)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, SIG_DFL);
|
||||||
sig_unblock(SIGCHLD);
|
sig_unblock(SIGCHLD);
|
||||||
sig_unblock(SIGTERM);
|
sig_unblock(SIGTERM);
|
||||||
execvp(*run, run);
|
execvp(*run, run);
|
||||||
@ -460,9 +462,9 @@ int runsv_main(int argc, char **argv)
|
|||||||
ndelay_on(selfpipe.wr);
|
ndelay_on(selfpipe.wr);
|
||||||
|
|
||||||
sig_block(SIGCHLD);
|
sig_block(SIGCHLD);
|
||||||
sig_catch(SIGCHLD, s_child);
|
bb_signals_recursive(1 << SIGCHLD, s_child);
|
||||||
sig_block(SIGTERM);
|
sig_block(SIGTERM);
|
||||||
sig_catch(SIGTERM, s_term);
|
bb_signals_recursive(1 << SIGTERM, s_term);
|
||||||
|
|
||||||
xchdir(dir);
|
xchdir(dir);
|
||||||
/* bss: svd[0].pid = 0; */
|
/* bss: svd[0].pid = 0; */
|
||||||
|
@ -100,8 +100,10 @@ static void runsv(int no, const char *name)
|
|||||||
/* child */
|
/* child */
|
||||||
if (set_pgrp)
|
if (set_pgrp)
|
||||||
setsid();
|
setsid();
|
||||||
signal(SIGHUP, SIG_DFL);
|
bb_signals(0
|
||||||
signal(SIGTERM, SIG_DFL);
|
+ (1 << SIGHUP)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, SIG_DFL);
|
||||||
execvp(prog[0], prog);
|
execvp(prog[0], prog);
|
||||||
fatal2_cannot("start runsv ", name);
|
fatal2_cannot("start runsv ", name);
|
||||||
}
|
}
|
||||||
@ -232,8 +234,8 @@ int runsvdir_main(int argc, char **argv)
|
|||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
sig_catch(SIGTERM, s_term);
|
bb_signals_recursive(1 << SIGTERM, s_term);
|
||||||
sig_catch(SIGHUP, s_hangup);
|
bb_signals_recursive(1 << SIGHUP, s_hangup);
|
||||||
svdir = *argv++;
|
svdir = *argv++;
|
||||||
if (argv && *argv) {
|
if (argv && *argv) {
|
||||||
rplog = *argv;
|
rplog = *argv;
|
||||||
|
@ -222,9 +222,11 @@ static unsigned processorstart(struct logdir *ld)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* child */
|
/* child */
|
||||||
signal(SIGTERM, SIG_DFL);
|
bb_signals(0
|
||||||
signal(SIGALRM, SIG_DFL);
|
+ (1 << SIGTERM)
|
||||||
signal(SIGHUP, SIG_DFL);
|
+ (1 << SIGALRM)
|
||||||
|
+ (1 << SIGHUP)
|
||||||
|
, SIG_DFL);
|
||||||
sig_unblock(SIGTERM);
|
sig_unblock(SIGTERM);
|
||||||
sig_unblock(SIGALRM);
|
sig_unblock(SIGALRM);
|
||||||
sig_unblock(SIGHUP);
|
sig_unblock(SIGHUP);
|
||||||
@ -903,10 +905,10 @@ int svlogd_main(int argc, char **argv)
|
|||||||
sigaddset(&blocked_sigset, SIGALRM);
|
sigaddset(&blocked_sigset, SIGALRM);
|
||||||
sigaddset(&blocked_sigset, SIGHUP);
|
sigaddset(&blocked_sigset, SIGHUP);
|
||||||
sigprocmask(SIG_BLOCK, &blocked_sigset, NULL);
|
sigprocmask(SIG_BLOCK, &blocked_sigset, NULL);
|
||||||
sig_catch(SIGTERM, sig_term_handler);
|
bb_signals_recursive(1 << SIGTERM, sig_term_handler);
|
||||||
sig_catch(SIGCHLD, sig_child_handler);
|
bb_signals_recursive(1 << SIGCHLD, sig_child_handler);
|
||||||
sig_catch(SIGALRM, sig_alarm_handler);
|
bb_signals_recursive(1 << SIGALRM, sig_alarm_handler);
|
||||||
sig_catch(SIGHUP, sig_hangup_handler);
|
bb_signals_recursive(1 << SIGHUP, sig_hangup_handler);
|
||||||
|
|
||||||
logdirs_reopen();
|
logdirs_reopen();
|
||||||
|
|
||||||
|
36
shell/hush.c
36
shell/hush.c
@ -709,28 +709,34 @@ static void signal_SA_RESTART(int sig, void (*handler)(int))
|
|||||||
/* Signals are grouped, we handle them in batches */
|
/* Signals are grouped, we handle them in batches */
|
||||||
static void set_fatal_sighandler(void (*handler)(int))
|
static void set_fatal_sighandler(void (*handler)(int))
|
||||||
{
|
{
|
||||||
signal(SIGILL , handler);
|
bb_signals(0
|
||||||
signal(SIGTRAP, handler);
|
+ (1 << SIGILL)
|
||||||
signal(SIGABRT, handler);
|
+ (1 << SIGTRAP)
|
||||||
signal(SIGFPE , handler);
|
+ (1 << SIGABRT)
|
||||||
signal(SIGBUS , handler);
|
+ (1 << SIGFPE)
|
||||||
signal(SIGSEGV, handler);
|
+ (1 << SIGBUS)
|
||||||
|
+ (1 << SIGSEGV)
|
||||||
/* bash 3.2 seems to handle these just like 'fatal' ones */
|
/* bash 3.2 seems to handle these just like 'fatal' ones */
|
||||||
signal(SIGHUP , handler);
|
+ (1 << SIGHUP)
|
||||||
signal(SIGPIPE, handler);
|
+ (1 << SIGPIPE)
|
||||||
signal(SIGALRM, handler);
|
+ (1 << SIGALRM)
|
||||||
|
, handler);
|
||||||
}
|
}
|
||||||
static void set_jobctrl_sighandler(void (*handler)(int))
|
static void set_jobctrl_sighandler(void (*handler)(int))
|
||||||
{
|
{
|
||||||
signal(SIGTSTP, handler);
|
bb_signals(0
|
||||||
signal(SIGTTIN, handler);
|
+ (1 << SIGTSTP)
|
||||||
signal(SIGTTOU, handler);
|
+ (1 << SIGTTIN)
|
||||||
|
+ (1 << SIGTTOU)
|
||||||
|
, handler);
|
||||||
}
|
}
|
||||||
static void set_misc_sighandler(void (*handler)(int))
|
static void set_misc_sighandler(void (*handler)(int))
|
||||||
{
|
{
|
||||||
signal(SIGINT , handler);
|
bb_signals(0
|
||||||
signal(SIGQUIT, handler);
|
+ (1 << SIGINT)
|
||||||
signal(SIGTERM, handler);
|
+ (1 << SIGQUIT)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, handler);
|
||||||
}
|
}
|
||||||
/* SIGCHLD is special and handled separately */
|
/* SIGCHLD is special and handled separately */
|
||||||
|
|
||||||
|
@ -57,9 +57,10 @@ int klogd_main(int argc, char **argv)
|
|||||||
openlog("kernel", 0, LOG_KERN);
|
openlog("kernel", 0, LOG_KERN);
|
||||||
|
|
||||||
/* Set up sig handlers */
|
/* Set up sig handlers */
|
||||||
signal(SIGINT, klogd_signal);
|
bb_signals(0
|
||||||
signal(SIGKILL, klogd_signal);
|
+ (1 << SIGINT)
|
||||||
signal(SIGTERM, klogd_signal);
|
+ (1 << SIGTERM)
|
||||||
|
, klogd_signal);
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
|
|
||||||
/* "Open the log. Currently a NOP." */
|
/* "Open the log. Currently a NOP." */
|
||||||
|
@ -540,9 +540,11 @@ static void do_syslogd(void)
|
|||||||
int sock_fd;
|
int sock_fd;
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
signal(SIGINT, quit_signal);
|
bb_signals(0
|
||||||
signal(SIGTERM, quit_signal);
|
+ (1 << SIGINT)
|
||||||
signal(SIGQUIT, quit_signal);
|
+ (1 << SIGTERM)
|
||||||
|
+ (1 << SIGQUIT)
|
||||||
|
, quit_signal);
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
/* signal(SIGCHLD, SIG_IGN); - why? */
|
/* signal(SIGCHLD, SIG_IGN); - why? */
|
||||||
#ifdef SYSLOGD_MARK
|
#ifdef SYSLOGD_MARK
|
||||||
|
@ -87,9 +87,11 @@ int more_main(int argc, char **argv)
|
|||||||
new_settings.c_cc[VMIN] = 1;
|
new_settings.c_cc[VMIN] = 1;
|
||||||
new_settings.c_cc[VTIME] = 0;
|
new_settings.c_cc[VTIME] = 0;
|
||||||
setTermSettings(cin_fileno, &new_settings);
|
setTermSettings(cin_fileno, &new_settings);
|
||||||
signal(SIGINT, gotsig);
|
bb_signals(0
|
||||||
signal(SIGQUIT, gotsig);
|
+ (1 << SIGINT)
|
||||||
signal(SIGTERM, gotsig);
|
+ (1 << SIGQUIT)
|
||||||
|
+ (1 << SIGTERM)
|
||||||
|
, gotsig);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
Loading…
Reference in New Issue
Block a user