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>
16 #include <sys/resource.h>
18 /* Was a CONFIG_xxx option. A lot of people were building
19 * not fully functional init by switching it on! */
22 #define COMMAND_SIZE 256
23 #define CONSOLE_NAME_SIZE 32
26 #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
29 /* Allowed init action types */
32 /* like respawn, but wait for <Enter> to be pressed on tty: */
36 #define CTRLALTDEL 0x20
40 /* Set up a linked list of init_actions, to be read from inittab */
42 struct init_action *next;
45 char terminal[CONSOLE_NAME_SIZE];
46 char command[COMMAND_SIZE];
49 static struct init_action *init_action_list = NULL;
51 static const char *log_console = VC_5;
56 MAYBE_CONSOLE = L_CONSOLE * !ENABLE_FEATURE_EXTRA_QUIET,
57 #ifndef RB_HALT_SYSTEM
58 RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
59 RB_ENABLE_CAD = 0x89abcdef,
61 RB_POWER_OFF = 0x4321fedc,
62 RB_AUTOBOOT = 0x01234567,
66 static void halt_reboot_pwoff(int sig) NORETURN;
68 static void loop_forever(void) NORETURN;
69 static void loop_forever(void)
75 /* Print a message to the specified device.
76 * "where" may be bitwise-or'd from L_LOG | L_CONSOLE
77 * NB: careful, we can be called after vfork!
79 #define messageD(...) do { if (DEBUG_INIT) message(__VA_ARGS__); } while (0)
80 static void message(int where, const char *fmt, ...)
81 __attribute__ ((format(printf, 2, 3)));
82 static void message(int where, const char *fmt, ...)
84 static int log_fd = -1;
90 va_start(arguments, fmt);
91 l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
92 if (l > sizeof(msg) - 1)
97 if (ENABLE_FEATURE_INIT_SYSLOG) {
99 /* Log the message to syslogd */
100 openlog("init", 0, LOG_DAEMON);
101 /* don't print "\r" */
102 syslog(LOG_INFO, "%s", msg + 1);
110 /* Take full control of the log tty, and never close it.
111 * It's mine, all mine! Muhahahaha! */
114 log_fd = STDERR_FILENO;
116 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
118 bb_error_msg("can't log to %s", log_console);
121 close_on_exec_on(log_fd);
126 full_write(log_fd, msg, l);
127 if (log_fd == STDERR_FILENO)
128 return; /* don't print dup messages */
132 if (where & L_CONSOLE) {
133 /* Send console messages to console so people will see them. */
134 full_write(STDERR_FILENO, msg, l);
138 /* From <linux/serial.h> */
139 struct serial_struct {
148 unsigned short close_delay;
150 char reserved_char[1];
152 unsigned short closing_wait; /* time to wait before closing */
153 unsigned short closing_wait2; /* no longer used... */
154 unsigned char *iomem_base;
155 unsigned short iomem_reg_shift;
156 unsigned int port_high;
157 unsigned long iomap_base; /* cookie passed into ioremap */
159 /* Paranoia (imagine 64bit kernel overwriting 32bit userspace stack) */
160 uint32_t bbox_reserved[16];
162 static void console_init(void)
164 struct serial_struct sr;
167 s = getenv("CONSOLE");
169 s = getenv("console");
171 int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY);
173 dup2(fd, STDIN_FILENO);
174 dup2(fd, STDOUT_FILENO);
175 xmove_fd(fd, STDERR_FILENO);
177 messageD(L_LOG, "console='%s'", s);
179 /* Make sure fd 0,1,2 are not closed
180 * (so that they won't be used by future opens) */
182 // Users report problems
183 // /* Make sure init can't be blocked by writing to stderr */
184 // fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
188 if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) {
189 /* Force the TERM setting to vt102 for serial console
190 * if TERM is set to linux (the default) */
191 if (!s || strcmp(s, "linux") == 0)
192 putenv((char*)"TERM=vt102");
193 if (!ENABLE_FEATURE_INIT_SYSLOG)
196 putenv((char*)"TERM=linux");
199 /* Set terminal settings to reasonable defaults.
200 * NB: careful, we can be called after vfork! */
201 static void set_sane_term(void)
205 tcgetattr(STDIN_FILENO, &tty);
207 /* set control chars */
208 tty.c_cc[VINTR] = 3; /* C-c */
209 tty.c_cc[VQUIT] = 28; /* C-\ */
210 tty.c_cc[VERASE] = 127; /* C-? */
211 tty.c_cc[VKILL] = 21; /* C-u */
212 tty.c_cc[VEOF] = 4; /* C-d */
213 tty.c_cc[VSTART] = 17; /* C-q */
214 tty.c_cc[VSTOP] = 19; /* C-s */
215 tty.c_cc[VSUSP] = 26; /* C-z */
217 /* use line discipline 0 */
220 /* Make it be sane */
221 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
222 tty.c_cflag |= CREAD | HUPCL | CLOCAL;
225 tty.c_iflag = ICRNL | IXON | IXOFF;
228 tty.c_oflag = OPOST | ONLCR;
232 ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
234 tcsetattr_stdin_TCSANOW(&tty);
237 /* Open the new terminal device.
238 * NB: careful, we can be called after vfork! */
239 static void open_stdio_to_tty(const char* tty_name, int exit_on_failure)
241 /* empty tty_name means "use init's tty", else... */
245 /* fd can be only < 0 or 0: */
246 fd = device_open(tty_name, O_RDWR);
248 message(L_LOG | L_CONSOLE, "can't open %s: %s",
249 tty_name, strerror(errno));
254 /* NB: we don't reach this if we were called after vfork.
255 * Thus halt_reboot_pwoff() itself need not be vfork-safe. */
256 halt_reboot_pwoff(SIGUSR1); /* halt the system */
258 dup2(STDIN_FILENO, STDOUT_FILENO);
259 dup2(STDIN_FILENO, STDERR_FILENO);
264 /* Wrapper around exec:
265 * Takes string (max COMMAND_SIZE chars).
266 * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'.
267 * Otherwise splits words on whitespace, deals with leading dash,
268 * and uses plain exec().
269 * NB: careful, we can be called after vfork!
271 static void init_exec(const char *command)
273 char *cmd[COMMAND_SIZE / 2];
274 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
275 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
277 /* See if any special /bin/sh requiring characters are present */
278 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
279 strcpy(buf, "exec ");
280 strcpy(buf + 5, command + dash); /* excluding "-" */
281 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
282 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
283 cmd[1] = (char*)"-c";
287 /* Convert command (char*) into cmd (char**, one word per string) */
290 next = strcpy(buf, command); /* including "-" */
291 while ((word = strsep(&next, " \t")) != NULL) {
292 if (*word != '\0') { /* not two spaces/tabs together? */
299 /* If we saw leading "-", it is interactive shell.
300 * Try harder to give it a controlling tty.
301 * And skip "-" in actual exec call. */
303 /* _Attempt_ to make stdin a controlling tty. */
304 if (ENABLE_FEATURE_INIT_SCTTY)
305 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
307 BB_EXECVP(cmd[0] + dash, cmd);
308 message(L_LOG | L_CONSOLE, "cannot run '%s': %s", cmd[0], strerror(errno));
309 /* returns if execvp fails */
312 /* Used only by run_actions */
313 static pid_t run(const struct init_action *a)
316 sigset_t nmask, omask;
318 /* Block sigchild while forking (why?) */
320 sigaddset(&nmask, SIGCHLD);
321 sigprocmask(SIG_BLOCK, &nmask, &omask);
322 if (BB_MMU && (a->action_type & ASKFIRST))
326 sigprocmask(SIG_SETMASK, &omask, NULL);
329 message(L_LOG | L_CONSOLE, "can't fork");
335 /* Reset signal handlers that were set by the parent process */
348 /* Create a new session and make ourself the process
352 /* Open the new terminal device */
353 open_stdio_to_tty(a->terminal, 1 /* - exit if open fails */);
355 // NB: do not enable unless you change vfork to fork above
356 #ifdef BUT_RUN_ACTIONS_ALREADY_DOES_WAITING
357 /* If the init Action requires us to wait, then force the
358 * supplied terminal to be the controlling tty. */
359 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
360 /* Now fork off another process to just hang around */
363 message(L_LOG | L_CONSOLE, "can't fork");
368 /* Parent - wait till the child is done */
374 signal(SIGCHLD, SIG_DFL);
377 /* See if stealing the controlling tty back is necessary */
378 if (tcgetpgrp(0) != getpid())
381 /* Use a temporary process to steal the controlling tty. */
384 message(L_LOG | L_CONSOLE, "can't fork");
389 ioctl(0, TIOCSCTTY, 1);
395 /* Child - fall though to actually execute things */
399 /* NB: on NOMMU we can't wait for input in child, so
400 * "askfirst" will work the same as "respawn". */
401 if (BB_MMU && (a->action_type & ASKFIRST)) {
402 static const char press_enter[] ALIGN1 =
403 #ifdef CUSTOMIZED_BANNER
404 #include CUSTOMIZED_BANNER
406 "\nPlease press Enter to activate this console. ";
409 * Save memory by not exec-ing anything large (like a shell)
410 * before the user wants it. This is critical if swap is not
411 * enabled and the system has low memory. Generally this will
412 * be run on the second virtual console, and the first will
413 * be allowed to start a shell or whatever an init script
416 messageD(L_LOG, "waiting for enter to start '%s'"
417 "(pid %d, tty '%s')\n",
418 a->command, getpid(), a->terminal);
419 full_write(STDOUT_FILENO, press_enter, sizeof(press_enter) - 1);
420 while (safe_read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
425 * When a file named /.init_enable_core exists, setrlimit is called
426 * before processes are spawned to set core file size as unlimited.
427 * This is for debugging only. Don't use this is production, unless
428 * you want core dumps lying about....
430 if (ENABLE_FEATURE_INIT_COREDUMPS) {
431 if (access("/.init_enable_core", F_OK) == 0) {
433 limit.rlim_cur = RLIM_INFINITY;
434 limit.rlim_max = RLIM_INFINITY;
435 setrlimit(RLIMIT_CORE, &limit);
439 /* Log the process name and args */
440 message(L_LOG, "starting pid %d, tty '%s': '%s'",
441 getpid(), a->terminal, a->command);
443 /* Now run it. The new program will take over this PID,
444 * so nothing further in init.c should be run. */
445 init_exec(a->command);
446 /* We're still here? Some error happened. */
450 static void delete_init_action(struct init_action *action)
452 struct init_action *a, *b = NULL;
454 for (a = init_action_list; a; b = a, a = a->next) {
457 init_action_list = a->next;
467 static void waitfor(pid_t pid)
469 /* waitfor(run(x)): protect against failed fork inside run() */
473 /* Wait for any child (prevent zombies from exiting orphaned processes)
474 * but exit the loop only when specified one has exited. */
475 while (wait(NULL) != pid)
479 /* Run all commands of a particular type */
480 static void run_actions(int action_type)
482 struct init_action *a, *tmp;
484 for (a = init_action_list; a; a = tmp) {
486 if (a->action_type & action_type) {
487 // Pointless: run() will error out if open of device fails.
488 ///* a->terminal of "" means "init's console" */
489 //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
490 // //message(L_LOG | L_CONSOLE, "Device %s cannot be opened in RW mode", a->terminal /*, strerror(errno)*/);
491 // delete_init_action(a);
493 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
495 delete_init_action(a);
496 } else if (a->action_type & ONCE) {
498 delete_init_action(a);
499 } else if (a->action_type & (RESPAWN | ASKFIRST)) {
500 /* Only run stuff with pid==0. If they have
501 * a pid, that means it is still running */
510 static void low_level_reboot(unsigned long magic)
513 /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in
514 * linux/kernel/sys.c, which can cause the machine to panic when
515 * the init process is killed.... */
517 if (pid == 0) { /* child */
524 static void kill_all_processes(void)
526 /* run everything to be run at "shutdown". This is done _prior_
527 * to killing everything, in case people wish to use scripts to
528 * shut things down gracefully... */
529 run_actions(SHUTDOWN);
531 /* first disable all our signals */
532 sigprocmask_allsigs(SIG_BLOCK);
534 message(L_CONSOLE | L_LOG, "The system is going down NOW!");
536 /* Allow Ctrl-Alt-Del to reboot system. */
537 low_level_reboot(RB_ENABLE_CAD);
539 /* Send signals to every process _except_ pid 1 */
540 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM");
545 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "KILL");
551 static void halt_reboot_pwoff(int sig)
553 const char *m = "halt";
556 kill_all_processes();
559 if (sig == SIGTERM) {
562 } else if (sig == SIGUSR2) {
566 message(L_CONSOLE | L_LOG, "Requesting system %s", m);
567 /* allow time for last message to reach serial console */
569 low_level_reboot(rb);
573 /* Handler for QUIT - exec "restart" action,
574 * else (no such action defined) do nothing */
575 static void restart_handler(int sig UNUSED_PARAM)
577 struct init_action *a;
579 for (a = init_action_list; a; a = a->next) {
580 if (a->action_type & RESTART) {
581 kill_all_processes();
583 /* unblock all signals (blocked in kill_all_processes()) */
584 sigprocmask_allsigs(SIG_UNBLOCK);
586 /* Open the new terminal device */
587 open_stdio_to_tty(a->terminal, 0 /* - halt if open fails */);
589 messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command);
590 init_exec(a->command);
592 low_level_reboot(RB_HALT_SYSTEM);
598 static void ctrlaltdel_signal(int sig UNUSED_PARAM)
600 run_actions(CTRLALTDEL);
603 /* The SIGCONT handler is set to record_signo().
604 * It just sets bb_got_signal = SIGCONT. */
606 /* The SIGSTOP & SIGTSTP handler */
607 static void stop_handler(int sig UNUSED_PARAM)
609 int saved_errno = errno;
612 while (bb_got_signal == 0)
618 static void new_init_action(uint8_t action_type, const char *command, const char *cons)
620 struct init_action *a, *last;
623 // if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
626 /* Append to the end of the list */
627 for (a = last = init_action_list; a; a = a->next) {
628 /* don't enter action if it's already in the list,
629 * but do overwrite existing actions */
630 if ((strcmp(a->command, command) == 0)
631 && (strcmp(a->terminal, cons) == 0)
633 a->action_type = action_type;
639 a = xzalloc(sizeof(*a));
643 init_action_list = a;
645 a->action_type = action_type;
646 safe_strncpy(a->command, command, sizeof(a->command));
647 safe_strncpy(a->terminal, cons, sizeof(a->terminal));
648 messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
649 a->command, a->action_type, a->terminal);
652 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
653 * then parse_inittab() simply adds in some default
654 * actions(i.e., runs INIT_SCRIPT and then starts a pair
655 * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB
656 * _is_ defined, but /etc/inittab is missing, this
657 * results in the same set of default behaviors.
659 static void parse_inittab(void)
661 #if ENABLE_FEATURE_USE_INITTAB
663 parser_t *parser = config_open2("/etc/inittab", fopen_for_read);
668 /* No inittab file -- set up some default behavior */
669 /* Reboot on Ctrl-Alt-Del */
670 new_init_action(CTRLALTDEL, "reboot", "");
671 /* Umount all filesystems on halt/reboot */
672 new_init_action(SHUTDOWN, "umount -a -r", "");
673 /* Swapoff on halt/reboot */
674 if (ENABLE_SWAPONOFF)
675 new_init_action(SHUTDOWN, "swapoff -a", "");
676 /* Prepare to restart init when a QUIT is received */
677 new_init_action(RESTART, "init", "");
678 /* Askfirst shell on tty1-4 */
679 new_init_action(ASKFIRST, bb_default_login_shell, "");
680 //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
681 new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
682 new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
683 new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
685 new_init_action(SYSINIT, INIT_SCRIPT, "");
689 #if ENABLE_FEATURE_USE_INITTAB
690 /* optional_tty:ignored_runlevel:action:command
691 * Delims are not to be collapsed and need exactly 4 tokens
693 while (config_read(parser, token, 4, 0, "#:",
694 PARSE_NORMAL & ~(PARSE_TRIM | PARSE_COLLAPSE))) {
695 /* order must correspond to SYSINIT..RESTART constants */
696 static const char actions[] ALIGN1 =
697 "sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
698 "ctrlaltdel\0""shutdown\0""restart\0";
700 char *tty = token[0];
702 if (!token[3]) /* less than 4 tokens */
704 action = index_in_strings(actions, token[2]);
705 if (action < 0 || !token[3][0]) /* token[3]: command */
707 /* turn .*TTY -> /dev/TTY */
709 if (strncmp(tty, "/dev/", 5) == 0)
711 tty = concat_path_file("/dev/", tty);
713 new_init_action(1 << action, token[3], tty);
718 message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d",
721 config_close(parser);
725 #if ENABLE_FEATURE_USE_INITTAB
726 static void reload_inittab(int sig UNUSED_PARAM)
728 struct init_action *a, *tmp;
730 message(L_LOG, "reloading /etc/inittab");
732 /* disable old entrys */
733 for (a = init_action_list; a; a = a->next) {
734 a->action_type = ONCE;
739 if (ENABLE_FEATURE_KILL_REMOVED) {
740 /* Be nice and send SIGTERM first */
741 for (a = init_action_list; a; a = a->next) {
743 if ((a->action_type & ONCE) && pid != 0) {
747 #if CONFIG_FEATURE_KILL_DELAY
748 /* NB: parent will wait in NOMMU case */
749 if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
750 sleep(CONFIG_FEATURE_KILL_DELAY);
751 for (a = init_action_list; a; a = a->next) {
753 if ((a->action_type & ONCE) && pid != 0) {
762 /* remove unused entrys */
763 for (a = init_action_list; a; a = tmp) {
765 if ((a->action_type & (ONCE | SYSINIT | WAIT)) && a->pid == 0) {
766 delete_init_action(a);
769 run_actions(RESPAWN | ASKFIRST);
772 void reload_inittab(int sig);
775 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
776 int init_main(int argc UNUSED_PARAM, char **argv)
778 struct init_action *a;
781 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
783 if (argv[1] && !strcmp(argv[1], "-q")) {
784 return kill(1, SIGHUP);
788 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
790 && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc"))
794 /* Set up sig handlers -- be sure to
795 * clear all of these in run() */
796 // TODO: handlers should just set a flag variable.
797 // Move signal handling from handlers to main loop -
798 // we have bad races otherwise.
799 // E.g. parse_inittab() vs. delete_init_action()...
800 signal(SIGQUIT, restart_handler);
802 + (1 << SIGUSR1) /* halt */
803 + (1 << SIGUSR2) /* poweroff */
804 + (1 << SIGTERM) /* reboot */
805 , halt_reboot_pwoff);
806 signal(SIGINT, ctrlaltdel_signal);
807 signal(SIGCONT, record_signo);
813 /* Turn off rebooting via CTL-ALT-DEL -- we get a
814 * SIGINT on CAD so we can shut things down gracefully... */
815 low_level_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) == 0
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.");
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 signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_inittab : SIG_IGN);
905 /* Now run the looping stuff for the rest of forever */
907 /* run the respawn/askfirst stuff */
908 run_actions(RESPAWN | ASKFIRST);
910 /* Don't consume all CPU time -- sleep a bit */
913 /* Wait for any child process to exit */
916 /* Find out who died and clean up their corpse */
917 for (a = init_action_list; a; a = a->next) {
918 if (a->pid == wpid) {
919 /* Set the pid to 0 so that the process gets
920 * restarted by run_actions() */
922 message(L_LOG, "process '%s' (pid %d) exited. "
923 "Scheduling for restart.",
927 /* see if anyone else is waiting to be reaped */
928 wpid = wait_any_nohang(NULL);