aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-01-02 19:55:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-01-02 19:55:04 +0000
commitfb0eba706cccd510d99c4c5339a76dd15bc8a628 (patch)
tree45122b93a1a5d628e4aa146251e34397094de817 /init
parent27963980dbe1262fd6c447fc7d06839aea0861bc (diff)
downloadbusybox-fb0eba706cccd510d99c4c5339a76dd15bc8a628.tar.gz
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')
-rw-r--r--init/init.c26
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[] = {
/* Function prototypes */
static void delete_init_action(struct init_action *a);
-static int waitfor(pid_t pid);
static void halt_reboot_pwoff(int sig) ATTRIBUTE_NORETURN;
+/* TODO: move to libbb? */
+static int waitfor(pid_t runpid)
+{
+ return safe_waitpid(runpid, NULL, 0);
+}
+
static void loop_forever(void) ATTRIBUTE_NORETURN;
static void loop_forever(void)
{
@@ -465,19 +470,6 @@ static pid_t run(const struct init_action *a)
_exit(-1);
}
-static int waitfor(pid_t runpid)
-{
- int status, wpid;
-
- while (1) {
- wpid = waitpid(runpid, &status, 0);
- if (wpid == -1 && errno == EINTR)
- continue;
- break;
- }
- return wpid;
-}
-
/* Run all commands of a particular type */
static void run_actions(int action)
{
@@ -520,7 +512,7 @@ static void init_reboot(unsigned long magic)
reboot(magic);
_exit(0);
}
- waitpid(pid, NULL, 0);
+ waitfor(pid);
}
static void kill_all_processes(void)
@@ -980,7 +972,7 @@ int init_main(int argc, char **argv)
/* Don't consume all CPU time -- sleep a bit */
sleep(1);
- /* Wait for a child process to exit */
+ /* Wait for any child process to exit */
wpid = wait(NULL);
while (wpid > 0) {
/* Find out who died and clean up their corpse */
@@ -995,7 +987,7 @@ int init_main(int argc, char **argv)
}
}
/* see if anyone else is waiting to be reaped */
- wpid = waitpid(-1, NULL, WNOHANG);
+ wpid = wait_any_nohang(NULL);
}
}
}