aboutsummaryrefslogtreecommitdiff
path: root/miscutils/time.c
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2008-02-16 22:58:56 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2008-02-16 22:58:56 +0000
commit25591c322c9305bd54d3ab80cfaf01ef87640d77 (patch)
tree66ce77758e35f4faa2d5f611d0535365f2cba00a /miscutils/time.c
parent7fc294cdfe1e7f4a12c44f984a698b0c0f609075 (diff)
downloadbusybox-25591c322c9305bd54d3ab80cfaf01ef87640d77.tar.gz
busybox-25591c322c9305bd54d3ab80cfaf01ef87640d77.tar.bz2
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/time.c')
-rw-r--r--miscutils/time.c16
1 files changed, 9 insertions, 7 deletions
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 =
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);