diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-01-02 19:55:04 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-01-02 19:55:04 +0000 |
commit | fb0eba706cccd510d99c4c5339a76dd15bc8a628 (patch) | |
tree | 45122b93a1a5d628e4aa146251e34397094de817 /init/init.c | |
parent | 27963980dbe1262fd6c447fc7d06839aea0861bc (diff) | |
download | busybox-w32-fb0eba706cccd510d99c4c5339a76dd15bc8a628.tar.gz busybox-w32-fb0eba706cccd510d99c4c5339a76dd15bc8a628.tar.bz2 busybox-w32-fb0eba706cccd510d99c4c5339a76dd15bc8a628.zip |
libbb: introduce and use safe_waitpid (loops in EINTR)
*: use more approproate (shorter) versions of wait()
function old new delta
safe_waitpid - 48 +48
wait_any_nohang - 17 +17
send_tree 365 369 +4
processorstop 432 435 +3
text_yank 110 108 -2
make_human_readable_str 202 200 -2
crond_main 1368 1366 -2
handle_sigchld 49 43 -6
reapchild 166 159 -7
custom 260 250 -10
checkscript 191 177 -14
wait_nohang 17 - -17
wait_pid 43 - -43
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/7 up/down: 72/-103) Total: -31 bytes
Diffstat (limited to 'init/init.c')
-rw-r--r-- | init/init.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/init/init.c b/init/init.c index 51125f348..68a59d88e 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -95,9 +95,14 @@ static const char *const environment[] = { | |||
95 | 95 | ||
96 | /* Function prototypes */ | 96 | /* Function prototypes */ |
97 | static void delete_init_action(struct init_action *a); | 97 | static void delete_init_action(struct init_action *a); |
98 | static int waitfor(pid_t pid); | ||
99 | static void halt_reboot_pwoff(int sig) ATTRIBUTE_NORETURN; | 98 | static void halt_reboot_pwoff(int sig) ATTRIBUTE_NORETURN; |
100 | 99 | ||
100 | /* TODO: move to libbb? */ | ||
101 | static int waitfor(pid_t runpid) | ||
102 | { | ||
103 | return safe_waitpid(runpid, NULL, 0); | ||
104 | } | ||
105 | |||
101 | static void loop_forever(void) ATTRIBUTE_NORETURN; | 106 | static void loop_forever(void) ATTRIBUTE_NORETURN; |
102 | static void loop_forever(void) | 107 | static void loop_forever(void) |
103 | { | 108 | { |
@@ -465,19 +470,6 @@ static pid_t run(const struct init_action *a) | |||
465 | _exit(-1); | 470 | _exit(-1); |
466 | } | 471 | } |
467 | 472 | ||
468 | static int waitfor(pid_t runpid) | ||
469 | { | ||
470 | int status, wpid; | ||
471 | |||
472 | while (1) { | ||
473 | wpid = waitpid(runpid, &status, 0); | ||
474 | if (wpid == -1 && errno == EINTR) | ||
475 | continue; | ||
476 | break; | ||
477 | } | ||
478 | return wpid; | ||
479 | } | ||
480 | |||
481 | /* Run all commands of a particular type */ | 473 | /* Run all commands of a particular type */ |
482 | static void run_actions(int action) | 474 | static void run_actions(int action) |
483 | { | 475 | { |
@@ -520,7 +512,7 @@ static void init_reboot(unsigned long magic) | |||
520 | reboot(magic); | 512 | reboot(magic); |
521 | _exit(0); | 513 | _exit(0); |
522 | } | 514 | } |
523 | waitpid(pid, NULL, 0); | 515 | waitfor(pid); |
524 | } | 516 | } |
525 | 517 | ||
526 | static void kill_all_processes(void) | 518 | static void kill_all_processes(void) |
@@ -980,7 +972,7 @@ int init_main(int argc, char **argv) | |||
980 | /* Don't consume all CPU time -- sleep a bit */ | 972 | /* Don't consume all CPU time -- sleep a bit */ |
981 | sleep(1); | 973 | sleep(1); |
982 | 974 | ||
983 | /* Wait for a child process to exit */ | 975 | /* Wait for any child process to exit */ |
984 | wpid = wait(NULL); | 976 | wpid = wait(NULL); |
985 | while (wpid > 0) { | 977 | while (wpid > 0) { |
986 | /* Find out who died and clean up their corpse */ | 978 | /* Find out who died and clean up their corpse */ |
@@ -995,7 +987,7 @@ int init_main(int argc, char **argv) | |||
995 | } | 987 | } |
996 | } | 988 | } |
997 | /* see if anyone else is waiting to be reaped */ | 989 | /* see if anyone else is waiting to be reaped */ |
998 | wpid = waitpid(-1, NULL, WNOHANG); | 990 | wpid = wait_any_nohang(NULL); |
999 | } | 991 | } |
1000 | } | 992 | } |
1001 | } | 993 | } |