diff options
author | Denis Vlasenko | 2008-02-16 22:58:56 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-02-16 22:58:56 +0000 |
commit | 25591c322c9305bd54d3ab80cfaf01ef87640d77 (patch) | |
tree | 66ce77758e35f4faa2d5f611d0535365f2cba00a /miscutils | |
parent | 7fc294cdfe1e7f4a12c44f984a698b0c0f609075 (diff) | |
download | busybox-25591c322c9305bd54d3ab80cfaf01ef87640d77.zip busybox-25591c322c9305bd54d3ab80cfaf01ef87640d77.tar.gz |
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
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/less.c | 6 | ||||
-rw-r--r-- | miscutils/microcom.c | 10 | ||||
-rw-r--r-- | miscutils/time.c | 16 | ||||
-rw-r--r-- | miscutils/watchdog.c | 6 |
4 files changed, 23 insertions, 15 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 5ffebcd..85c5ec5 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -1355,8 +1355,10 @@ int less_main(int argc, char **argv) empty_line_marker = ""; tcgetattr(kbd_fd, &term_orig); - signal(SIGTERM, sig_catcher); - signal(SIGINT, sig_catcher); + bb_signals(0 + + (1 << SIGTERM) + + (1 << SIGINT) + , sig_catcher); term_less = term_orig; term_less.c_lflag &= ~(ICANON | ECHO); term_less.c_iflag &= ~(IXON | ICRNL); diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 63b07fd..b9ed9e4 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c @@ -99,10 +99,12 @@ int microcom_main(int argc, char **argv) } // setup signals - sig_catch(SIGHUP, signal_handler); - sig_catch(SIGINT, signal_handler); - sig_catch(SIGTERM, signal_handler); - sig_catch(SIGPIPE, signal_handler); + bb_signals_recursive(0 + + (1 << SIGHUP) + + (1 << SIGINT) + + (1 << SIGTERM) + + (1 << SIGPIPE) + , signal_handler); // error exit code if we fail to open the device signalled = 1; diff --git a/miscutils/time.c b/miscutils/time.c index d21944e..677ca6d 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -61,7 +61,7 @@ static const char long_format[] ALIGN1 = Return 0 on error, 1 if ok. */ /* 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; 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 returns the child process, set the time the command finished. */ while ((caught = wait3(&status, 0, &resp->ru)) != pid) { - if (caught == -1) + if (caught == -1 && errno != EINTR) return 0; } 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. 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. */ - __sighandler_t interrupt_signal, quit_signal; + void (*interrupt_signal)(int); + void (*quit_signal)(int); resp->elapsed_ms = monotonic_us() / 1000; pid = vfork(); /* Run CMD as child process. */ if (pid < 0) 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, versus merely warnings if the cast is left off. */ BB_EXECVP(cmd[0], cmd); - bb_error_msg("cannot run %s", cmd[0]); - _exit(errno == ENOENT ? 127 : 126); + xfunc_error_retval = (errno == ENOENT ? 127 : 126); + bb_error_msg_and_die("cannot run %s", cmd[0]); } /* 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); quit_signal = signal(SIGQUIT, SIG_IGN); diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index e040c64..28bd358 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c @@ -47,8 +47,10 @@ int watchdog_main(int argc, char **argv) bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); } - signal(SIGHUP, watchdog_shutdown); - signal(SIGINT, watchdog_shutdown); + bb_signals(0 + + (1 << SIGHUP) + + (1 << SIGINT) + , watchdog_shutdown); /* Use known fd # - avoid needing global 'int fd' */ xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); |