summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/less.c6
-rw-r--r--miscutils/microcom.c10
-rw-r--r--miscutils/time.c16
-rw-r--r--miscutils/watchdog.c6
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);