1 /* vi: set sw=4 ts=4: */
3 * Mini init implementation for busybox
5 * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
6 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Adjusted by so many folks, it's impossible to keep track.
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
15 #include <sys/reboot.h>
17 #define COMMAND_SIZE 256
18 #define CONSOLE_NAME_SIZE 32
19 #define MAXENV 16 /* Number of env. vars */
22 * When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
23 * before processes are spawned to set core file size as unlimited.
24 * This is for debugging only. Don't use this is production, unless
25 * you want core dumps lying about....
27 #define CORE_ENABLE_FLAG_FILE "/.init_enable_core"
28 #include <sys/resource.h>
30 #define INITTAB "/etc/inittab" /* inittab file location */
32 #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
35 /* Allowed init action types */
38 /* like respawn, but wait for <Enter> to be pressed on tty: */
42 #define CTRLALTDEL 0x20
46 /* Set up a linked list of init_actions, to be read from inittab */
48 struct init_action *next;
51 char terminal[CONSOLE_NAME_SIZE];
52 char command[COMMAND_SIZE];
55 /* Static variables */
56 static struct init_action *init_action_list = NULL;
58 static const char *log_console = VC_5;
59 static sig_atomic_t got_cont = 0;
65 #if ENABLE_FEATURE_EXTRA_QUIET
68 MAYBE_CONSOLE = L_CONSOLE,
71 #ifndef RB_HALT_SYSTEM
72 RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
73 RB_ENABLE_CAD = 0x89abcdef,
75 RB_POWER_OFF = 0x4321fedc,
76 RB_AUTOBOOT = 0x01234567,
80 /* Function prototypes */
81 static void halt_reboot_pwoff(int sig) NORETURN;
83 static void waitfor(pid_t pid)
85 /* waitfor(run(x)): protect against failed fork inside run() */
89 /* Wait for any child (prevent zombies from exiting orphaned processes)
90 * but exit the loop only when specified one has exited. */
91 while (wait(NULL) != pid)
95 static void loop_forever(void) NORETURN;
96 static void loop_forever(void)
102 /* Print a message to the specified device.
103 * "where" may be bitwise-or'd from L_LOG | L_CONSOLE
104 * NB: careful, we can be called after vfork!
106 #define messageD(...) do { if (ENABLE_DEBUG_INIT) message(__VA_ARGS__); } while (0)
107 static void message(int where, const char *fmt, ...)
108 __attribute__ ((format(printf, 2, 3)));
109 static void message(int where, const char *fmt, ...)
111 static int log_fd = -1;
117 va_start(arguments, fmt);
118 l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
119 if (l > sizeof(msg) - 2)
124 if (ENABLE_FEATURE_INIT_SYSLOG) {
125 /* Log the message to syslogd */
127 /* don't print out "\r" */
128 openlog(applet_name, 0, LOG_DAEMON);
129 syslog(LOG_INFO, "init: %s", msg + 1);
137 /* Take full control of the log tty, and never close it.
138 * It's mine, all mine! Muhahahaha! */
141 log_fd = STDERR_FILENO;
143 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
145 bb_error_msg("can't log to %s", log_console);
148 close_on_exec_on(log_fd);
153 full_write(log_fd, msg, l);
154 if (log_fd == STDERR_FILENO)
155 return; /* don't print dup messages */
159 if (where & L_CONSOLE) {
160 /* Send console messages to console so people will see them. */
161 full_write(STDERR_FILENO, msg, l);
165 /* From <linux/serial.h> */
166 struct serial_struct {
175 unsigned short close_delay;
177 char reserved_char[1];
179 unsigned short closing_wait; /* time to wait before closing */
180 unsigned short closing_wait2; /* no longer used... */
181 unsigned char *iomem_base;
182 unsigned short iomem_reg_shift;
183 unsigned int port_high;
184 unsigned long iomap_base; /* cookie passed into ioremap */
186 /* Paranoia (imagine 64bit kernel overwriting 32bit userspace stack) */
187 uint32_t bbox_reserved[16];
189 static void console_init(void)
191 struct serial_struct sr;
194 s = getenv("CONSOLE");
196 s = getenv("console");
198 int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY);
200 dup2(fd, STDIN_FILENO);
201 dup2(fd, STDOUT_FILENO);
202 xmove_fd(fd, STDERR_FILENO);
204 messageD(L_LOG, "console='%s'", s);
206 /* Make sure fd 0,1,2 are not closed
207 * (so that they won't be used by future opens) */
209 /* Make sure init can't be blocked by writing to stderr */
210 fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
214 if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) {
215 /* Force the TERM setting to vt102 for serial console
216 * if TERM is set to linux (the default) */
217 if (!s || strcmp(s, "linux") == 0)
218 putenv((char*)"TERM=vt102");
219 if (!ENABLE_FEATURE_INIT_SYSLOG)
222 putenv((char*)"TERM=linux");
225 /* Set terminal settings to reasonable defaults.
226 * NB: careful, we can be called after vfork! */
227 static void set_sane_term(void)
231 tcgetattr(STDIN_FILENO, &tty);
233 /* set control chars */
234 tty.c_cc[VINTR] = 3; /* C-c */
235 tty.c_cc[VQUIT] = 28; /* C-\ */
236 tty.c_cc[VERASE] = 127; /* C-? */
237 tty.c_cc[VKILL] = 21; /* C-u */
238 tty.c_cc[VEOF] = 4; /* C-d */
239 tty.c_cc[VSTART] = 17; /* C-q */
240 tty.c_cc[VSTOP] = 19; /* C-s */
241 tty.c_cc[VSUSP] = 26; /* C-z */
243 /* use line discipline 0 */
246 /* Make it be sane */
247 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
248 tty.c_cflag |= CREAD | HUPCL | CLOCAL;
251 tty.c_iflag = ICRNL | IXON | IXOFF;
254 tty.c_oflag = OPOST | ONLCR;
258 ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
260 tcsetattr(STDIN_FILENO, TCSANOW, &tty);
263 /* Open the new terminal device.
264 * NB: careful, we can be called after vfork! */
265 static void open_stdio_to_tty(const char* tty_name, int exit_on_failure)
267 /* empty tty_name means "use init's tty", else... */
271 /* fd can be only < 0 or 0: */
272 fd = device_open(tty_name, O_RDWR);
274 message(L_LOG | L_CONSOLE, "can't open %s: %s",
275 tty_name, strerror(errno));
278 if (ENABLE_DEBUG_INIT)
280 /* NB: we don't reach this if we were called after vfork.
281 * Thus halt_reboot_pwoff() itself need not be vfork-safe. */
282 halt_reboot_pwoff(SIGUSR1); /* halt the system */
284 dup2(STDIN_FILENO, STDOUT_FILENO);
285 dup2(STDIN_FILENO, STDERR_FILENO);
290 /* Wrapper around exec:
291 * Takes string (max COMMAND_SIZE chars).
292 * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'.
293 * Otherwise splits words on whitespace, deals with leading dash,
294 * and uses plain exec().
295 * NB: careful, we can be called after vfork!
297 static void init_exec(const char *command)
299 char *cmd[COMMAND_SIZE / 2];
300 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
301 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
303 /* See if any special /bin/sh requiring characters are present */
304 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
305 strcpy(buf, "exec ");
306 strcpy(buf + 5, command + dash); /* excluding "-" */
307 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
308 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
309 cmd[1] = (char*)"-c";
313 /* Convert command (char*) into cmd (char**, one word per string) */
316 next = strcpy(buf, command); /* including "-" */
317 while ((word = strsep(&next, " \t")) != NULL) {
318 if (*word != '\0') { /* not two spaces/tabs together? */
325 /* If we saw leading "-", it is interactive shell.
326 * Try harder to give it a controlling tty.
327 * And skip "-" in actual exec call. */
329 /* _Attempt_ to make stdin a controlling tty. */
330 if (ENABLE_FEATURE_INIT_SCTTY)
331 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
333 BB_EXECVP(cmd[0] + dash, cmd);
334 message(L_LOG | L_CONSOLE, "cannot run '%s': %s", cmd[0], strerror(errno));
335 /* returns if execvp fails */
338 /* Used only by run_actions */
339 static pid_t run(const struct init_action *a)
342 sigset_t nmask, omask;
344 /* Block sigchild while forking (why?) */
346 sigaddset(&nmask, SIGCHLD);
347 sigprocmask(SIG_BLOCK, &nmask, &omask);
348 if (BB_MMU && (a->action_type & ASKFIRST))
352 sigprocmask(SIG_SETMASK, &omask, NULL);
355 message(L_LOG | L_CONSOLE, "can't fork");
361 /* Reset signal handlers that were set by the parent process */
374 /* Create a new session and make ourself the process
378 /* Open the new terminal device */
379 open_stdio_to_tty(a->terminal, 1 /* - exit if open fails */);
381 // NB: do not enable unless you change vfork to fork above
382 #ifdef BUT_RUN_ACTIONS_ALREADY_DOES_WAITING
383 /* If the init Action requires us to wait, then force the
384 * supplied terminal to be the controlling tty. */
385 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
386 /* Now fork off another process to just hang around */
389 message(L_LOG | L_CONSOLE, "can't fork");
394 /* Parent - wait till the child is done */
400 signal(SIGCHLD, SIG_DFL);
403 /* See if stealing the controlling tty back is necessary */
404 if (tcgetpgrp(0) != getpid())
407 /* Use a temporary process to steal the controlling tty. */
410 message(L_LOG | L_CONSOLE, "can't fork");
415 ioctl(0, TIOCSCTTY, 1);
421 /* Child - fall though to actually execute things */
425 /* NB: on NOMMU we can't wait for input in child, so
426 * "askfirst" will work the same as "respawn". */
427 if (BB_MMU && (a->action_type & ASKFIRST)) {
428 static const char press_enter[] ALIGN1 =
429 #ifdef CUSTOMIZED_BANNER
430 #include CUSTOMIZED_BANNER
432 "\nPlease press Enter to activate this console. ";
435 * Save memory by not exec-ing anything large (like a shell)
436 * before the user wants it. This is critical if swap is not
437 * enabled and the system has low memory. Generally this will
438 * be run on the second virtual console, and the first will
439 * be allowed to start a shell or whatever an init script
442 messageD(L_LOG, "waiting for enter to start '%s'"
443 "(pid %d, tty '%s')\n",
444 a->command, getpid(), a->terminal);
445 full_write(STDOUT_FILENO, press_enter, sizeof(press_enter) - 1);
446 while (safe_read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
450 if (ENABLE_FEATURE_INIT_COREDUMPS) {
452 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
454 limit.rlim_cur = RLIM_INFINITY;
455 limit.rlim_max = RLIM_INFINITY;
456 setrlimit(RLIMIT_CORE, &limit);
460 /* Log the process name and args */
461 message(L_LOG, "starting pid %d, tty '%s': '%s'",
462 getpid(), a->terminal, a->command);
464 /* Now run it. The new program will take over this PID,
465 * so nothing further in init.c should be run. */
466 init_exec(a->command);
467 /* We're still here? Some error happened. */
471 static void delete_init_action(struct init_action *action)
473 struct init_action *a, *b = NULL;
475 for (a = init_action_list; a; b = a, a = a->next) {
478 init_action_list = a->next;
488 /* Run all commands of a particular type */
489 static void run_actions(int action_type)
491 struct init_action *a, *tmp;
493 for (a = init_action_list; a; a = tmp) {
495 if (a->action_type & action_type) {
496 // Pointless: run() will error out if open of device fails.
497 ///* a->terminal of "" means "init's console" */
498 //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
499 // //message(L_LOG | L_CONSOLE, "Device %s cannot be opened in RW mode", a->terminal /*, strerror(errno)*/);
500 // delete_init_action(a);
502 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
504 delete_init_action(a);
505 } else if (a->action_type & ONCE) {
507 delete_init_action(a);
508 } else if (a->action_type & (RESPAWN | ASKFIRST)) {
509 /* Only run stuff with pid==0. If they have
510 * a pid, that means it is still running */
519 static void init_reboot(unsigned long magic)
522 /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in
523 * linux/kernel/sys.c, which can cause the machine to panic when
524 * the init process is killed.... */
526 if (pid == 0) { /* child */
533 static void kill_all_processes(void)
535 /* run everything to be run at "shutdown". This is done _prior_
536 * to killing everything, in case people wish to use scripts to
537 * shut things down gracefully... */
538 run_actions(SHUTDOWN);
540 /* first disable all our signals */
541 sigprocmask_allsigs(SIG_BLOCK);
543 message(L_CONSOLE | L_LOG, "The system is going down NOW!");
545 /* Allow Ctrl-Alt-Del to reboot system. */
546 init_reboot(RB_ENABLE_CAD);
548 /* Send signals to every process _except_ pid 1 */
549 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM");
554 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "KILL");
560 static void halt_reboot_pwoff(int sig)
562 const char *m = "halt";
565 kill_all_processes();
568 if (sig == SIGTERM) {
571 } else if (sig == SIGUSR2) {
575 message(L_CONSOLE | L_LOG, "Requesting system %s", m);
576 /* allow time for last message to reach serial console */
582 /* Handler for QUIT - exec "restart" action,
583 * else (no such action defined) do nothing */
584 static void exec_restart_action(int sig UNUSED_PARAM)
586 struct init_action *a;
588 for (a = init_action_list; a; a = a->next) {
589 if (a->action_type & RESTART) {
590 kill_all_processes();
592 /* unblock all signals (blocked in kill_all_processes()) */
593 sigprocmask_allsigs(SIG_UNBLOCK);
595 /* Open the new terminal device */
596 open_stdio_to_tty(a->terminal, 0 /* - halt if open fails */);
598 messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command);
599 init_exec(a->command);
601 init_reboot(RB_HALT_SYSTEM);
607 static void ctrlaltdel_signal(int sig UNUSED_PARAM)
609 run_actions(CTRLALTDEL);
612 /* The SIGSTOP & SIGTSTP handler */
613 static void stop_handler(int sig UNUSED_PARAM)
615 int saved_errno = errno;
624 /* The SIGCONT handler */
625 static void cont_handler(int sig UNUSED_PARAM)
630 static void new_init_action(uint8_t action_type, const char *command, const char *cons)
632 struct init_action *a, *last;
635 // if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
638 /* Append to the end of the list */
639 for (a = last = init_action_list; a; a = a->next) {
640 /* don't enter action if it's already in the list,
641 * but do overwrite existing actions */
642 if ((strcmp(a->command, command) == 0)
643 && (strcmp(a->terminal, cons) == 0)
645 a->action_type = action_type;
651 a = xzalloc(sizeof(*a));
655 init_action_list = a;
657 a->action_type = action_type;
658 safe_strncpy(a->command, command, sizeof(a->command));
659 safe_strncpy(a->terminal, cons, sizeof(a->terminal));
660 messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
661 a->command, a->action_type, a->terminal);
664 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
665 * then parse_inittab() simply adds in some default
666 * actions(i.e., runs INIT_SCRIPT and then starts a pair
667 * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB
668 * _is_ defined, but /etc/inittab is missing, this
669 * results in the same set of default behaviors.
671 static void parse_inittab(void)
674 /* order must correspond to SYSINIT..RESTART constants */
675 static const char actions[] ALIGN1 =
676 "sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
677 "ctrlaltdel\0""shutdown\0""restart\0";
679 parser_t *parser = config_open2(INITTAB, fopen_for_read);
680 /* No inittab file -- set up some default behavior */
681 if (parser == NULL) {
682 /* Reboot on Ctrl-Alt-Del */
683 new_init_action(CTRLALTDEL, "reboot", "");
684 /* Umount all filesystems on halt/reboot */
685 new_init_action(SHUTDOWN, "umount -a -r", "");
686 /* Swapoff on halt/reboot */
687 if (ENABLE_SWAPONOFF)
688 new_init_action(SHUTDOWN, "swapoff -a", "");
689 /* Prepare to restart init when a QUIT is received */
690 new_init_action(RESTART, "init", "");
691 /* Askfirst shell on tty1-4 */
692 new_init_action(ASKFIRST, bb_default_login_shell, "");
693 //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
694 new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
695 new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
696 new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
698 new_init_action(SYSINIT, INIT_SCRIPT, "");
701 /* optional_tty:ignored_runlevel:action:command
702 * Delims are not to be collapsed and need exactly 4 tokens
704 while (config_read(parser, token, 4, 0, "#:",
705 PARSE_NORMAL & ~(PARSE_TRIM | PARSE_COLLAPSE))) {
707 char *tty = token[0];
709 if (!token[3]) /* less than 4 tokens */
711 action = index_in_strings(actions, token[2]);
712 if (action < 0 || !token[3][0]) /* token[3]: command */
714 /* turn .*TTY -> /dev/TTY */
716 if (strncmp(tty, "/dev/", 5) == 0)
718 tty = concat_path_file("/dev/", tty);
720 new_init_action(1 << action, token[3], tty);
725 message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d",
728 config_close(parser);
731 #if ENABLE_FEATURE_USE_INITTAB
732 static void reload_signal(int sig UNUSED_PARAM)
734 struct init_action *a, *tmp;
736 message(L_LOG, "reloading /etc/inittab");
738 /* disable old entrys */
739 for (a = init_action_list; a; a = a->next) {
740 a->action_type = ONCE;
745 if (ENABLE_FEATURE_KILL_REMOVED) {
746 /* Be nice and send SIGTERM first */
747 for (a = init_action_list; a; a = a->next) {
749 if ((a->action_type & ONCE) && pid != 0) {
753 #if CONFIG_FEATURE_KILL_DELAY
754 /* NB: parent will wait in NOMMU case */
755 if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
756 sleep(CONFIG_FEATURE_KILL_DELAY);
757 for (a = init_action_list; a; a = a->next) {
759 if ((a->action_type & ONCE) && pid != 0) {
768 /* remove unused entrys */
769 for (a = init_action_list; a; a = tmp) {
771 if ((a->action_type & (ONCE | SYSINIT | WAIT)) && a->pid == 0) {
772 delete_init_action(a);
775 run_actions(RESPAWN | ASKFIRST);
779 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
780 int init_main(int argc UNUSED_PARAM, char **argv)
782 struct init_action *a;
785 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
787 if (argv[1] && !strcmp(argv[1], "-q")) {
788 return kill(1, SIGHUP);
791 if (!ENABLE_DEBUG_INIT) {
792 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
794 && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc"))
798 /* Set up sig handlers -- be sure to
799 * clear all of these in run() */
800 signal(SIGQUIT, exec_restart_action);
802 + (1 << SIGUSR1) /* halt */
803 + (1 << SIGUSR2) /* poweroff */
804 + (1 << SIGTERM) /* reboot */
805 , halt_reboot_pwoff);
806 signal(SIGINT, ctrlaltdel_signal);
807 signal(SIGCONT, cont_handler);
813 /* Turn off rebooting via CTL-ALT-DEL -- we get a
814 * SIGINT on CAD so we can shut things down gracefully... */
815 init_reboot(RB_DISABLE_CAD);
818 /* Figure out where the default console should be */
824 /* Make sure environs is set to something sane */
825 putenv((char *) "HOME=/");
826 putenv((char *) bb_PATH_root_path);
827 putenv((char *) "SHELL=/bin/sh");
828 putenv((char *) "USER=root"); /* needed? why? */
831 xsetenv("RUNLEVEL", argv[1]);
834 message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);
836 /* Make sure there is enough memory to do something useful. */
837 if (ENABLE_SWAPONOFF) {
840 if (!sysinfo(&info) &&
841 (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024)
843 message(L_CONSOLE, "Low memory, forcing swapon");
844 /* swapon -a requires /proc typically */
845 new_init_action(SYSINIT, "mount -t proc proc /proc", "");
846 /* Try to turn on swap */
847 new_init_action(SYSINIT, "swapon -a", "");
848 run_actions(SYSINIT); /* wait and removing */
852 /* Check if we are supposed to be in single user mode */
854 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
856 /* ??? shouldn't we set RUNLEVEL="b" here? */
857 /* Start a shell on console */
858 new_init_action(RESPAWN, bb_default_login_shell, "");
860 /* Not in single user mode -- see what inittab says */
862 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
863 * then parse_inittab() simply adds in some default
864 * actions(i.e., runs INIT_SCRIPT and then starts a pair
865 * of "askfirst" shells */
870 if (getenv("SELINUX_INIT") == NULL) {
873 putenv((char*)"SELINUX_INIT=YES");
874 if (selinux_init_load_policy(&enforce) == 0) {
875 BB_EXECVP(argv[0], argv);
876 } else if (enforce > 0) {
877 /* SELinux in enforcing mode but load_policy failed */
878 message(L_CONSOLE, "cannot load SELinux Policy. "
879 "Machine is in enforcing mode. Halting now.");
883 #endif /* CONFIG_SELINUX */
885 /* Make the command line just say "init" - thats all, nothing else */
886 strncpy(argv[0], "init", strlen(argv[0]));
887 /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
889 memset(*argv, 0, strlen(*argv));
891 /* Now run everything that needs to be run */
893 /* First run the sysinit command */
894 run_actions(SYSINIT);
896 /* Next run anything that wants to block */
899 /* Next run anything to be run only once */
902 /* Redefine SIGHUP to reread /etc/inittab */
903 #if ENABLE_FEATURE_USE_INITTAB
904 signal(SIGHUP, reload_signal);
906 signal(SIGHUP, SIG_IGN);
909 /* Now run the looping stuff for the rest of forever */
911 /* run the respawn/askfirst stuff */
912 run_actions(RESPAWN | ASKFIRST);
914 /* Don't consume all CPU time -- sleep a bit */
917 /* Wait for any child process to exit */
920 /* Find out who died and clean up their corpse */
921 for (a = init_action_list; a; a = a->next) {
922 if (a->pid == wpid) {
923 /* Set the pid to 0 so that the process gets
924 * restarted by run_actions() */
926 message(L_LOG, "process '%s' (pid %d) exited. "
927 "Scheduling for restart.",
931 /* see if anyone else is waiting to be reaped */
932 wpid = wait_any_nohang(NULL);