void bb_signals(int sigs, void (*f)(int)) FAST_FUNC;
/* Unlike signal() and bb_signals, sets handler with sigaction()
* and in a way that while signal handler is run, no other signals
- * will be blocked: */
-void bb_signals_recursive(int sigs, void (*f)(int)) FAST_FUNC;
+ * will be blocked; syscalls will not be restarted: */
+void bb_signals_recursive_norestart(int sigs, void (*f)(int)) FAST_FUNC;
/* syscalls like read() will be interrupted with EINTR: */
void signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int)) FAST_FUNC;
/* syscalls like read() won't be interrupted (though select/poll will be): */
static void halt_reboot_pwoff(int sig) 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) NORETURN;
static void loop_forever(void)
{
}
}
+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;
+}
+
/* Run all commands of a particular type */
static void run_actions(int action_type)
{
}
}
-static void init_reboot(unsigned long magic)
+static void low_level_reboot(unsigned long magic)
{
pid_t pid;
/* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in
message(L_CONSOLE | L_LOG, "The system is going down NOW!");
/* Allow Ctrl-Alt-Del to reboot system. */
- init_reboot(RB_ENABLE_CAD);
+ low_level_reboot(RB_ENABLE_CAD);
/* Send signals to every process _except_ pid 1 */
message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM");
message(L_CONSOLE | L_LOG, "Requesting system %s", m);
/* allow time for last message to reach serial console */
sleep(2);
- init_reboot(rb);
+ low_level_reboot(rb);
loop_forever();
}
/* Handler for QUIT - exec "restart" action,
* else (no such action defined) do nothing */
-static void exec_restart_action(int sig UNUSED_PARAM)
+static void restart_handler(int sig UNUSED_PARAM)
{
struct init_action *a;
messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command);
init_exec(a->command);
sleep(2);
- init_reboot(RB_HALT_SYSTEM);
+ low_level_reboot(RB_HALT_SYSTEM);
loop_forever();
}
}
}
#if ENABLE_FEATURE_USE_INITTAB
-static void reload_signal(int sig UNUSED_PARAM)
+static void reload_inittab(int sig UNUSED_PARAM)
{
struct init_action *a, *tmp;
run_actions(RESPAWN | ASKFIRST);
}
#else
-void reload_signal(int sig);
+void reload_inittab(int sig);
#endif
int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
// Move signal handling from handlers to main loop -
// we have bad races otherwise.
// E.g. parse_inittab() vs. delete_init_action()...
- signal(SIGQUIT, exec_restart_action);
+ signal(SIGQUIT, restart_handler);
bb_signals(0
+ (1 << SIGUSR1) /* halt */
+ (1 << SIGUSR2) /* poweroff */
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
- init_reboot(RB_DISABLE_CAD);
+ low_level_reboot(RB_DISABLE_CAD);
}
/* Figure out where the default console should be */
run_actions(ONCE);
/* Redefine SIGHUP to reread /etc/inittab */
- signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_signal : SIG_IGN);
+ signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_inittab : SIG_IGN);
/* Now run the looping stuff for the rest of forever */
while (1) {
sigaddset(&blocked_sigset, SIGALRM);
sigaddset(&blocked_sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &blocked_sigset, NULL);
- bb_signals_recursive(1 << SIGTERM, sig_term_handler);
- bb_signals_recursive(1 << SIGCHLD, sig_child_handler);
- bb_signals_recursive(1 << SIGALRM, sig_alarm_handler);
- bb_signals_recursive(1 << SIGHUP, sig_hangup_handler);
+ bb_signals_recursive_norestart(1 << SIGTERM, sig_term_handler);
+ bb_signals_recursive_norestart(1 << SIGCHLD, sig_child_handler);
+ bb_signals_recursive_norestart(1 << SIGALRM, sig_alarm_handler);
+ bb_signals_recursive_norestart(1 << SIGHUP, sig_hangup_handler);
logdirs_reopen();