/* 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;
+static void waitfor(pid_t pid)
+{
+ /* waitfor(run(x)): protect against failed fork inside run() */
+ if (pid <= 0)
+ return;
+
+ /* Wait for any child (prevent zombies from exiting orphaned processes)
+ * but exit the loop only when specified one has exited. */
+ while (wait(NULL) != pid)
+ continue;
+}
+
static void loop_forever(void) ATTRIBUTE_NORETURN;
static void loop_forever(void)
{
_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)
{
reboot(magic);
_exit(0);
}
- waitpid(pid, NULL, 0);
+ waitfor(pid);
}
static void kill_all_processes(void)
/* 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 */
}
}
/* see if anyone else is waiting to be reaped */
- wpid = waitpid(-1, NULL, WNOHANG);
+ wpid = wait_any_nohang(NULL);
}
}
}