aboutsummaryrefslogtreecommitdiff
path: root/miscutils/time.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-16 22:58:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-16 22:58:56 +0000
commit25591c322c9305bd54d3ab80cfaf01ef87640d77 (patch)
tree66ce77758e35f4faa2d5f611d0535365f2cba00a /miscutils/time.c
parent7fc294cdfe1e7f4a12c44f984a698b0c0f609075 (diff)
downloadbusybox-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/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 =
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. */
64static int resuse_end(pid_t pid, resource_t * resp) 64static 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. */
376static void run_command(char *const *cmd, resource_t * resp) 376static 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