diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-16 22:58:56 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-16 22:58:56 +0000 |
commit | 25591c322c9305bd54d3ab80cfaf01ef87640d77 (patch) | |
tree | 66ce77758e35f4faa2d5f611d0535365f2cba00a /miscutils | |
parent | 7fc294cdfe1e7f4a12c44f984a698b0c0f609075 (diff) | |
download | busybox-w32-25591c322c9305bd54d3ab80cfaf01ef87640d77.tar.gz busybox-w32-25591c322c9305bd54d3ab80cfaf01ef87640d77.tar.bz2 busybox-w32-25591c322c9305bd54d3ab80cfaf01ef87640d77.zip |
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 5ffebcd6d..85c5ec536 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -1355,8 +1355,10 @@ int less_main(int argc, char **argv) | |||
1355 | empty_line_marker = ""; | 1355 | empty_line_marker = ""; |
1356 | 1356 | ||
1357 | tcgetattr(kbd_fd, &term_orig); | 1357 | tcgetattr(kbd_fd, &term_orig); |
1358 | signal(SIGTERM, sig_catcher); | 1358 | bb_signals(0 |
1359 | signal(SIGINT, sig_catcher); | 1359 | + (1 << SIGTERM) |
1360 | + (1 << SIGINT) | ||
1361 | , sig_catcher); | ||
1360 | term_less = term_orig; | 1362 | term_less = term_orig; |
1361 | term_less.c_lflag &= ~(ICANON | ECHO); | 1363 | term_less.c_lflag &= ~(ICANON | ECHO); |
1362 | term_less.c_iflag &= ~(IXON | ICRNL); | 1364 | term_less.c_iflag &= ~(IXON | ICRNL); |
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 63b07fd69..b9ed9e401 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -99,10 +99,12 @@ int microcom_main(int argc, char **argv) | |||
99 | } | 99 | } |
100 | 100 | ||
101 | // setup signals | 101 | // setup signals |
102 | sig_catch(SIGHUP, signal_handler); | 102 | bb_signals_recursive(0 |
103 | sig_catch(SIGINT, signal_handler); | 103 | + (1 << SIGHUP) |
104 | sig_catch(SIGTERM, signal_handler); | 104 | + (1 << SIGINT) |
105 | sig_catch(SIGPIPE, signal_handler); | 105 | + (1 << SIGTERM) |
106 | + (1 << SIGPIPE) | ||
107 | , signal_handler); | ||
106 | 108 | ||
107 | // error exit code if we fail to open the device | 109 | // error exit code if we fail to open the device |
108 | signalled = 1; | 110 | signalled = 1; |
diff --git a/miscutils/time.c b/miscutils/time.c index d21944e01..677ca6d8b 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
@@ -61,7 +61,7 @@ static const char long_format[] ALIGN1 = | |||
61 | Return 0 on error, 1 if ok. */ | 61 | Return 0 on error, 1 if ok. */ |
62 | 62 | ||
63 | /* pid_t is short on BSDI, so don't try to promote it. */ | 63 | /* pid_t is short on BSDI, so don't try to promote it. */ |
64 | static int resuse_end(pid_t pid, resource_t * resp) | 64 | static int resuse_end(pid_t pid, resource_t *resp) |
65 | { | 65 | { |
66 | int status; | 66 | int status; |
67 | pid_t caught; | 67 | pid_t caught; |
@@ -69,7 +69,7 @@ static int resuse_end(pid_t pid, resource_t * resp) | |||
69 | /* Ignore signals, but don't ignore the children. When wait3 | 69 | /* Ignore signals, but don't ignore the children. When wait3 |
70 | returns the child process, set the time the command finished. */ | 70 | returns the child process, set the time the command finished. */ |
71 | while ((caught = wait3(&status, 0, &resp->ru)) != pid) { | 71 | while ((caught = wait3(&status, 0, &resp->ru)) != pid) { |
72 | if (caught == -1) | 72 | if (caught == -1 && errno != EINTR) |
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | resp->elapsed_ms = (monotonic_us() / 1000) - resp->elapsed_ms; | 75 | resp->elapsed_ms = (monotonic_us() / 1000) - resp->elapsed_ms; |
@@ -373,24 +373,26 @@ static void summarize(const char *fmt, char **command, resource_t * resp) | |||
373 | 373 | ||
374 | /* Run command CMD and return statistics on it. | 374 | /* Run command CMD and return statistics on it. |
375 | Put the statistics in *RESP. */ | 375 | Put the statistics in *RESP. */ |
376 | static void run_command(char *const *cmd, resource_t * resp) | 376 | static void run_command(char *const *cmd, resource_t *resp) |
377 | { | 377 | { |
378 | pid_t pid; /* Pid of child. */ | 378 | pid_t pid; /* Pid of child. */ |
379 | __sighandler_t interrupt_signal, quit_signal; | 379 | void (*interrupt_signal)(int); |
380 | void (*quit_signal)(int); | ||
380 | 381 | ||
381 | resp->elapsed_ms = monotonic_us() / 1000; | 382 | resp->elapsed_ms = monotonic_us() / 1000; |
382 | pid = vfork(); /* Run CMD as child process. */ | 383 | pid = vfork(); /* Run CMD as child process. */ |
383 | if (pid < 0) | 384 | if (pid < 0) |
384 | bb_error_msg_and_die("cannot fork"); | 385 | bb_error_msg_and_die("cannot fork"); |
385 | else if (pid == 0) { /* If child. */ | 386 | if (pid == 0) { /* If child. */ |
386 | /* Don't cast execvp arguments; that causes errors on some systems, | 387 | /* Don't cast execvp arguments; that causes errors on some systems, |
387 | versus merely warnings if the cast is left off. */ | 388 | versus merely warnings if the cast is left off. */ |
388 | BB_EXECVP(cmd[0], cmd); | 389 | BB_EXECVP(cmd[0], cmd); |
389 | bb_error_msg("cannot run %s", cmd[0]); | 390 | xfunc_error_retval = (errno == ENOENT ? 127 : 126); |
390 | _exit(errno == ENOENT ? 127 : 126); | 391 | bb_error_msg_and_die("cannot run %s", cmd[0]); |
391 | } | 392 | } |
392 | 393 | ||
393 | /* Have signals kill the child but not self (if possible). */ | 394 | /* Have signals kill the child but not self (if possible). */ |
395 | //TODO: just block all sigs? and reenable them in the very end in main? | ||
394 | interrupt_signal = signal(SIGINT, SIG_IGN); | 396 | interrupt_signal = signal(SIGINT, SIG_IGN); |
395 | quit_signal = signal(SIGQUIT, SIG_IGN); | 397 | quit_signal = signal(SIGQUIT, SIG_IGN); |
396 | 398 | ||
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index e040c64fd..28bd35813 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c | |||
@@ -47,8 +47,10 @@ int watchdog_main(int argc, char **argv) | |||
47 | bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); | 47 | bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); |
48 | } | 48 | } |
49 | 49 | ||
50 | signal(SIGHUP, watchdog_shutdown); | 50 | bb_signals(0 |
51 | signal(SIGINT, watchdog_shutdown); | 51 | + (1 << SIGHUP) |
52 | + (1 << SIGINT) | ||
53 | , watchdog_shutdown); | ||
52 | 54 | ||
53 | /* Use known fd # - avoid needing global 'int fd' */ | 55 | /* Use known fd # - avoid needing global 'int fd' */ |
54 | xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); | 56 | xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); |