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 /* Was a CONFIG_xxx option. A lot of people were building
18 * not fully functional init by switching it on! */
21 #define COMMAND_SIZE 256
22 #define CONSOLE_NAME_SIZE 32
23 #define MAXENV 16 /* Number of env. vars */
26 * When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
27 * before processes are spawned to set core file size as unlimited.
28 * This is for debugging only. Don't use this is production, unless
29 * you want core dumps lying about....
31 #define CORE_ENABLE_FLAG_FILE "/.init_enable_core"
32 #include <sys/resource.h>
34 #define INITTAB "/etc/inittab" /* inittab file location */
36 #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
39 /* Allowed init action types */
42 /* like respawn, but wait for <Enter> to be pressed on tty: */
46 #define CTRLALTDEL 0x20
50 /* Set up a linked list of init_actions, to be read from inittab */
52 struct init_action *next;
55 char terminal[CONSOLE_NAME_SIZE];
56 char command[COMMAND_SIZE];
59 /* Static variables */
60 static struct init_action *init_action_list = NULL;
62 static const char *log_console = VC_5;
67 MAYBE_CONSOLE = L_CONSOLE * !ENABLE_FEATURE_EXTRA_QUIET,
68 #ifndef RB_HALT_SYSTEM
69 RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
70 RB_ENABLE_CAD = 0x89abcdef,
72 RB_POWER_OFF = 0x4321fedc,
73 RB_AUTOBOOT = 0x01234567,
77 /* Function prototypes */
78 static void halt_reboot_pwoff(int sig) NORETURN;
80 static void waitfor(pid_t pid)
82 /* waitfor(run(x)): protect against failed fork inside run() */
86 /* Wait for any child (prevent zombies from exiting orphaned processes)
87 * but exit the loop only when specified one has exited. */
88 while (wait(NULL) != pid)
92 static void loop_forever(void) NORETURN;
93 static void loop_forever(void)
99 /* Print a message to the specified device.
100 * "where" may be bitwise-or'd from L_LOG | L_CONSOLE
101 * NB: careful, we can be called after vfork!
103 #define messageD(...) do { if (DEBUG_INIT) message(__VA_ARGS__); } while (0)
104 static void message(int where, const char *fmt, ...)
105 __attribute__ ((format(printf, 2, 3)));
106 static void message(int where, const char *fmt, ...)
108 static int log_fd = -1;
114 va_start(arguments, fmt);
115 l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
116 if (l > sizeof(msg) - 1)
121 if (ENABLE_FEATURE_INIT_SYSLOG) {
123 /* Log the message to syslogd */
124 openlog("init", 0, LOG_DAEMON);
125 /* don't print "\r" */
126 syslog(LOG_INFO, "%s", msg + 1);
134 /* Take full control of the log tty, and never close it.
135 * It's mine, all mine! Muhahahaha! */
138 log_fd = STDERR_FILENO;
140 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
142 bb_error_msg("can't log to %s", log_console);
145 close_on_exec_on(log_fd);
150 full_write(log_fd, msg, l);
151 if (log_fd == STDERR_FILENO)
152 return; /* don't print dup messages */
156 if (where & L_CONSOLE) {
157 /* Send console messages to console so people will see them. */
158 full_write(STDERR_FILENO, msg, l);
162 /* From <linux/serial.h> */
163 struct serial_struct {
172 unsigned short close_delay;
174 char reserved_char[1];
176 unsigned short closing_wait; /* time to wait before closing */
177 unsigned short closing_wait2; /* no longer used... */
178 unsigned char *iomem_base;
179 unsigned short iomem_reg_shift;
180 unsigned int port_high;
181 unsigned long iomap_base; /* cookie passed into ioremap */
183 /* Paranoia (imagine 64bit kernel overwriting 32bit userspace stack) */
184 uint32_t bbox_reserved[16];
186 static void console_init(void)
188 struct serial_struct sr;
191 s = getenv("CONSOLE");
193 s = getenv("console");
195 int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY);
197 dup2(fd, STDIN_FILENO);
198 dup2(fd, STDOUT_FILENO);
199 xmove_fd(fd, STDERR_FILENO);
201 messageD(L_LOG, "console='%s'", s);
203 /* Make sure fd 0,1,2 are not closed
204 * (so that they won't be used by future opens) */
206 // Users report problems
207 // /* Make sure init can't be blocked by writing to stderr */
208 // fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
212 if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) {
213 /* Force the TERM setting to vt102 for serial console
214 * if TERM is set to linux (the default) */
215 if (!s || strcmp(s, "linux") == 0)
216 putenv((char*)"TERM=vt102");
217 if (!ENABLE_FEATURE_INIT_SYSLOG)
220 putenv((char*)"TERM=linux");
223 /* Set terminal settings to reasonable defaults.
224 * NB: careful, we can be called after vfork! */
225 static void set_sane_term(void)
229 tcgetattr(STDIN_FILENO, &tty);
231 /* set control chars */
232 tty.c_cc[VINTR] = 3; /* C-c */
233 tty.c_cc[VQUIT] = 28; /* C-\ */
234 tty.c_cc[VERASE] = 127; /* C-? */
235 tty.c_cc[VKILL] = 21; /* C-u */
236 tty.c_cc[VEOF] = 4; /* C-d */
237 tty.c_cc[VSTART] = 17; /* C-q */
238 tty.c_cc[VSTOP] = 19; /* C-s */
239 tty.c_cc[VSUSP] = 26; /* C-z */
241 /* use line discipline 0 */
244 /* Make it be sane */
245 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
246 tty.c_cflag |= CREAD | HUPCL | CLOCAL;
249 tty.c_iflag = ICRNL | IXON | IXOFF;
252 tty.c_oflag = OPOST | ONLCR;
256 ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
258 tcsetattr_stdin_TCSANOW(&tty);
261 /* Open the new terminal device.
262 * NB: careful, we can be called after vfork! */
263 static void open_stdio_to_tty(const char* tty_name, int exit_on_failure)
265 /* empty tty_name means "use init's tty", else... */
269 /* fd can be only < 0 or 0: */
270 fd = device_open(tty_name, O_RDWR);
272 message(L_LOG | L_CONSOLE, "can't open %s: %s",
273 tty_name, strerror(errno));
278 /* NB: we don't reach this if we were called after vfork.
279 * Thus halt_reboot_pwoff() itself need not be vfork-safe. */
280 halt_reboot_pwoff(SIGUSR1); /* halt the system */
282 dup2(STDIN_FILENO, STDOUT_FILENO);
283 dup2(STDIN_FILENO, STDERR_FILENO);
288 /* Wrapper around exec:
289 * Takes string (max COMMAND_SIZE chars).
290 * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'.
291 * Otherwise splits words on whitespace, deals with leading dash,
292 * and uses plain exec().
293 * NB: careful, we can be called after vfork!
295 static void init_exec(const char *command)
297 char *cmd[COMMAND_SIZE / 2];
298 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
299 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
301 /* See if any special /bin/sh requiring characters are present */
302 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
303 strcpy(buf, "exec ");
304 strcpy(buf + 5, command + dash); /* excluding "-" */
305 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
306 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
307 cmd[1] = (char*)"-c";
311 /* Convert command (char*) into cmd (char**, one word per string) */
314 next = strcpy(buf, command); /* including "-" */
315 while ((word = strsep(&next, " \t")) != NULL) {
316 if (*word != '\0') { /* not two spaces/tabs together? */
323 /* If we saw leading "-", it is interactive shell.
324 * Try harder to give it a controlling tty.
325 * And skip "-" in actual exec call. */
327 /* _Attempt_ to make stdin a controlling tty. */
328 if (ENABLE_FEATURE_INIT_SCTTY)
329 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
331 BB_EXECVP(cmd[0] + dash, cmd);
332 message(L_LOG | L_CONSOLE, "cannot run '%s': %s", cmd[0], strerror(errno));
333 /* returns if execvp fails */
336 /* Used only by run_actions */
337 static pid_t run(const struct init_action *a)
340 sigset_t nmask, omask;
342 /* Block sigchild while forking (why?) */
344 sigaddset(&nmask, SIGCHLD);
345 sigprocmask(SIG_BLOCK, &nmask, &omask);
346 if (BB_MMU && (a->action_type & ASKFIRST))
350 sigprocmask(SIG_SETMASK, &omask, NULL);
353 message(L_LOG | L_CONSOLE, "can't fork");
359 /* Reset signal handlers that were set by the parent process */
372 /* Create a new session and make ourself the process
376 /* Open the new terminal device */
377 open_stdio_to_tty(a->terminal, 1 /* - exit if open fails */);
379 // NB: do not enable unless you change vfork to fork above
380 #ifdef BUT_RUN_ACTIONS_ALREADY_DOES_WAITING
381 /* If the init Action requires us to wait, then force the
382 * supplied terminal to be the controlling tty. */
383 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
384 /* Now fork off another process to just hang around */
387 message(L_LOG | L_CONSOLE, "can't fork");
392 /* Parent - wait till the child is done */
398 signal(SIGCHLD, SIG_DFL);
401 /* See if stealing the controlling tty back is necessary */
402 if (tcgetpgrp(0) != getpid())
405 /* Use a temporary process to steal the controlling tty. */
408 message(L_LOG | L_CONSOLE, "can't fork");
413 ioctl(0, TIOCSCTTY, 1);
419 /* Child - fall though to actually execute things */
423 /* NB: on NOMMU we can't wait for input in child, so
424 * "askfirst" will work the same as "respawn". */
425 if (BB_MMU && (a->action_type & ASKFIRST)) {
426 static const char press_enter[] ALIGN1 =
427 #ifdef CUSTOMIZED_BANNER
428 #include CUSTOMIZED_BANNER
430 "\nPlease press Enter to activate this console. ";
433 * Save memory by not exec-ing anything large (like a shell)
434 * before the user wants it. This is critical if swap is not
435 * enabled and the system has low memory. Generally this will
436 * be run on the second virtual console, and the first will
437 * be allowed to start a shell or whatever an init script
440 messageD(L_LOG, "waiting for enter to start '%s'"
441 "(pid %d, tty '%s')\n",
442 a->command, getpid(), a->terminal);
443 full_write(STDOUT_FILENO, press_enter, sizeof(press_enter) - 1);
444 while (safe_read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
448 if (ENABLE_FEATURE_INIT_COREDUMPS) {
450 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
452 limit.rlim_cur = RLIM_INFINITY;
453 limit.rlim_max = RLIM_INFINITY;
454 setrlimit(RLIMIT_CORE, &limit);
458 /* Log the process name and args */
459 message(L_LOG, "starting pid %d, tty '%s': '%s'",
460 getpid(), a->terminal, a->command);
462 /* Now run it. The new program will take over this PID,
463 * so nothing further in init.c should be run. */
464 init_exec(a->command);
465 /* We're still here? Some error happened. */
469 static void delete_init_action(struct init_action *action)
471 struct init_action *a, *b = NULL;
473 for (a = init_action_list; a; b = a, a = a->next) {
476 init_action_list = a->next;
486 /* Run all commands of a particular type */
487 static void run_actions(int action_type)
489 struct init_action *a, *tmp;
491 for (a = init_action_list; a; a = tmp) {
493 if (a->action_type & action_type) {
494 // Pointless: run() will error out if open of device fails.
495 ///* a->terminal of "" means "init's console" */
496 //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
497 // //message(L_LOG | L_CONSOLE, "Device %s cannot be opened in RW mode", a->terminal /*, strerror(errno)*/);
498 // delete_init_action(a);
500 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
502 delete_init_action(a);
503 } else if (a->action_type & ONCE) {
505 delete_init_action(a);
506 } else if (a->action_type & (RESPAWN | ASKFIRST)) {
507 /* Only run stuff with pid==0. If they have
508 * a pid, that means it is still running */
517 static void init_reboot(unsigned long magic)
520 /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in
521 * linux/kernel/sys.c, which can cause the machine to panic when
522 * the init process is killed.... */
524 if (pid == 0) { /* child */
531 static void kill_all_processes(void)
533 /* run everything to be run at "shutdown". This is done _prior_
534 * to killing everything, in case people wish to use scripts to
535 * shut things down gracefully... */
536 run_actions(SHUTDOWN);
538 /* first disable all our signals */
539 sigprocmask_allsigs(SIG_BLOCK);
541 message(L_CONSOLE | L_LOG, "The system is going down NOW!");
543 /* Allow Ctrl-Alt-Del to reboot system. */
544 init_reboot(RB_ENABLE_CAD);
546 /* Send signals to every process _except_ pid 1 */
547 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM");
552 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "KILL");
558 static void halt_reboot_pwoff(int sig)
560 const char *m = "halt";
563 kill_all_processes();
566 if (sig == SIGTERM) {
569 } else if (sig == SIGUSR2) {
573 message(L_CONSOLE | L_LOG, "Requesting system %s", m);
574 /* allow time for last message to reach serial console */
580 /* Handler for QUIT - exec "restart" action,
581 * else (no such action defined) do nothing */
582 static void exec_restart_action(int sig UNUSED_PARAM)
584 struct init_action *a;
586 for (a = init_action_list; a; a = a->next) {
587 if (a->action_type & RESTART) {
588 kill_all_processes();
590 /* unblock all signals (blocked in kill_all_processes()) */
591 sigprocmask_allsigs(SIG_UNBLOCK);
593 /* Open the new terminal device */
594 open_stdio_to_tty(a->terminal, 0 /* - halt if open fails */);
596 messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command);
597 init_exec(a->command);
599 init_reboot(RB_HALT_SYSTEM);
605 static void ctrlaltdel_signal(int sig UNUSED_PARAM)
607 run_actions(CTRLALTDEL);
610 /* The SIGCONT handler is set to record_signo().
611 * It just sets bb_got_signal = SIGCONT. */
613 /* The SIGSTOP & SIGTSTP handler */
614 static void stop_handler(int sig UNUSED_PARAM)
616 int saved_errno = errno;
619 while (bb_got_signal == 0)
625 static void new_init_action(uint8_t action_type, const char *command, const char *cons)
627 struct init_action *a, *last;
630 // if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
633 /* Append to the end of the list */
634 for (a = last = init_action_list; a; a = a->next) {
635 /* don't enter action if it's already in the list,
636 * but do overwrite existing actions */
637 if ((strcmp(a->command, command) == 0)
638 && (strcmp(a->terminal, cons) == 0)
640 a->action_type = action_type;
646 a = xzalloc(sizeof(*a));
650 init_action_list = a;
652 a->action_type = action_type;
653 safe_strncpy(a->command, command, sizeof(a->command));
654 safe_strncpy(a->terminal, cons, sizeof(a->terminal));
655 messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
656 a->command, a->action_type, a->terminal);
659 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
660 * then parse_inittab() simply adds in some default
661 * actions(i.e., runs INIT_SCRIPT and then starts a pair
662 * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB
663 * _is_ defined, but /etc/inittab is missing, this
664 * results in the same set of default behaviors.
666 static void parse_inittab(void)
669 /* order must correspond to SYSINIT..RESTART constants */
670 static const char actions[] ALIGN1 =
671 "sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
672 "ctrlaltdel\0""shutdown\0""restart\0";
674 parser_t *parser = config_open2(INITTAB, fopen_for_read);
675 /* No inittab file -- set up some default behavior */
676 if (parser == NULL) {
677 /* Reboot on Ctrl-Alt-Del */
678 new_init_action(CTRLALTDEL, "reboot", "");
679 /* Umount all filesystems on halt/reboot */
680 new_init_action(SHUTDOWN, "umount -a -r", "");
681 /* Swapoff on halt/reboot */
682 if (ENABLE_SWAPONOFF)
683 new_init_action(SHUTDOWN, "swapoff -a", "");
684 /* Prepare to restart init when a QUIT is received */
685 new_init_action(RESTART, "init", "");
686 /* Askfirst shell on tty1-4 */
687 new_init_action(ASKFIRST, bb_default_login_shell, "");
688 //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
689 new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
690 new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
691 new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
693 new_init_action(SYSINIT, INIT_SCRIPT, "");
696 /* optional_tty:ignored_runlevel:action:command
697 * Delims are not to be collapsed and need exactly 4 tokens
699 while (config_read(parser, token, 4, 0, "#:",
700 PARSE_NORMAL & ~(PARSE_TRIM | PARSE_COLLAPSE))) {
702 char *tty = token[0];
704 if (!token[3]) /* less than 4 tokens */
706 action = index_in_strings(actions, token[2]);
707 if (action < 0 || !token[3][0]) /* token[3]: command */
709 /* turn .*TTY -> /dev/TTY */
711 if (strncmp(tty, "/dev/", 5) == 0)
713 tty = concat_path_file("/dev/", tty);
715 new_init_action(1 << action, token[3], tty);
720 message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d",
723 config_close(parser);
726 #if ENABLE_FEATURE_USE_INITTAB
727 static void reload_signal(int sig UNUSED_PARAM)
729 struct init_action *a, *tmp;
731 message(L_LOG, "reloading /etc/inittab");
733 /* disable old entrys */
734 for (a = init_action_list; a; a = a->next) {
735 a->action_type = ONCE;
740 if (ENABLE_FEATURE_KILL_REMOVED) {
741 /* Be nice and send SIGTERM first */
742 for (a = init_action_list; a; a = a->next) {
744 if ((a->action_type & ONCE) && pid != 0) {
748 #if CONFIG_FEATURE_KILL_DELAY
749 /* NB: parent will wait in NOMMU case */
750 if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
751 sleep(CONFIG_FEATURE_KILL_DELAY);
752 for (a = init_action_list; a; a = a->next) {
754 if ((a->action_type & ONCE) && pid != 0) {
763 /* remove unused entrys */
764 for (a = init_action_list; a; a = tmp) {
766 if ((a->action_type & (ONCE | SYSINIT | WAIT)) && a->pid == 0) {
767 delete_init_action(a);
770 run_actions(RESPAWN | ASKFIRST);
773 void reload_signal(int sig);
776 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
777 int init_main(int argc UNUSED_PARAM, char **argv)
779 struct init_action *a;
782 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
784 if (argv[1] && !strcmp(argv[1], "-q")) {
785 return kill(1, SIGHUP);
789 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
791 && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc"))
795 /* Set up sig handlers -- be sure to
796 * clear all of these in run() */
797 signal(SIGQUIT, exec_restart_action);
799 + (1 << SIGUSR1) /* halt */
800 + (1 << SIGUSR2) /* poweroff */
801 + (1 << SIGTERM) /* reboot */
802 , halt_reboot_pwoff);
803 signal(SIGINT, ctrlaltdel_signal);
804 signal(SIGCONT, record_signo);
810 /* Turn off rebooting via CTL-ALT-DEL -- we get a
811 * SIGINT on CAD so we can shut things down gracefully... */
812 init_reboot(RB_DISABLE_CAD);
815 /* Figure out where the default console should be */
821 /* Make sure environs is set to something sane */
822 putenv((char *) "HOME=/");
823 putenv((char *) bb_PATH_root_path);
824 putenv((char *) "SHELL=/bin/sh");
825 putenv((char *) "USER=root"); /* needed? why? */
828 xsetenv("RUNLEVEL", argv[1]);
831 message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);
833 /* Make sure there is enough memory to do something useful. */
834 if (ENABLE_SWAPONOFF) {
837 if (!sysinfo(&info) &&
838 (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024)
840 message(L_CONSOLE, "Low memory, forcing swapon");
841 /* swapon -a requires /proc typically */
842 new_init_action(SYSINIT, "mount -t proc proc /proc", "");
843 /* Try to turn on swap */
844 new_init_action(SYSINIT, "swapon -a", "");
845 run_actions(SYSINIT); /* wait and removing */
849 /* Check if we are supposed to be in single user mode */
851 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
853 /* ??? shouldn't we set RUNLEVEL="b" here? */
854 /* Start a shell on console */
855 new_init_action(RESPAWN, bb_default_login_shell, "");
857 /* Not in single user mode -- see what inittab says */
859 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
860 * then parse_inittab() simply adds in some default
861 * actions(i.e., runs INIT_SCRIPT and then starts a pair
862 * of "askfirst" shells */
867 if (getenv("SELINUX_INIT") == NULL) {
870 putenv((char*)"SELINUX_INIT=YES");
871 if (selinux_init_load_policy(&enforce) == 0) {
872 BB_EXECVP(argv[0], argv);
873 } else if (enforce > 0) {
874 /* SELinux in enforcing mode but load_policy failed */
875 message(L_CONSOLE, "cannot load SELinux Policy. "
876 "Machine is in enforcing mode. Halting now.");
880 #endif /* CONFIG_SELINUX */
882 /* Make the command line just say "init" - thats all, nothing else */
883 strncpy(argv[0], "init", strlen(argv[0]));
884 /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
886 memset(*argv, 0, strlen(*argv));
888 /* Now run everything that needs to be run */
890 /* First run the sysinit command */
891 run_actions(SYSINIT);
893 /* Next run anything that wants to block */
896 /* Next run anything to be run only once */
899 /* Redefine SIGHUP to reread /etc/inittab */
900 signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_signal : SIG_IGN);
902 /* Now run the looping stuff for the rest of forever */
904 /* run the respawn/askfirst stuff */
905 run_actions(RESPAWN | ASKFIRST);
907 /* Don't consume all CPU time -- sleep a bit */
910 /* Wait for any child process to exit */
913 /* Find out who died and clean up their corpse */
914 for (a = init_action_list; a; a = a->next) {
915 if (a->pid == wpid) {
916 /* Set the pid to 0 so that the process gets
917 * restarted by run_actions() */
919 message(L_LOG, "process '%s' (pid %d) exited. "
920 "Scheduling for restart.",
924 /* see if anyone else is waiting to be reaped */
925 wpid = wait_any_nohang(NULL);