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 static const char *const environment[] = {
88 /* Function prototypes */
89 static void halt_reboot_pwoff(int sig) NORETURN;
91 static void waitfor(pid_t pid)
93 /* waitfor(run(x)): protect against failed fork inside run() */
97 /* Wait for any child (prevent zombies from exiting orphaned processes)
98 * but exit the loop only when specified one has exited. */
99 while (wait(NULL) != pid)
103 static void loop_forever(void) NORETURN;
104 static void loop_forever(void)
110 /* Print a message to the specified device.
111 * "where" may be bitwise-or'd from L_LOG | L_CONSOLE
112 * NB: careful, we can be called after vfork!
114 #define messageD(...) do { if (ENABLE_DEBUG_INIT) message(__VA_ARGS__); } while (0)
115 static void message(int where, const char *fmt, ...)
116 __attribute__ ((format(printf, 2, 3)));
117 static void message(int where, const char *fmt, ...)
119 static int log_fd = -1;
125 va_start(arguments, fmt);
126 vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
128 msg[sizeof(msg) - 2] = '\0';
131 if (ENABLE_FEATURE_INIT_SYSLOG) {
132 /* Log the message to syslogd */
134 /* don't print out "\r" */
135 openlog(applet_name, 0, LOG_DAEMON);
136 syslog(LOG_INFO, "init: %s", msg + 1);
144 /* Take full control of the log tty, and never close it.
145 * It's mine, all mine! Muhahahaha! */
148 log_fd = STDERR_FILENO;
150 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
152 bb_error_msg("can't log to %s", log_console);
155 close_on_exec_on(log_fd);
160 full_write(log_fd, msg, l);
161 if (log_fd == STDERR_FILENO)
162 return; /* don't print dup messages */
166 if (where & L_CONSOLE) {
167 /* Send console messages to console so people will see them. */
168 full_write(STDERR_FILENO, msg, l);
172 /* From <linux/serial.h> */
173 struct serial_struct {
182 unsigned short close_delay;
184 char reserved_char[1];
186 unsigned short closing_wait; /* time to wait before closing */
187 unsigned short closing_wait2; /* no longer used... */
188 unsigned char *iomem_base;
189 unsigned short iomem_reg_shift;
190 unsigned int port_high;
191 unsigned long iomap_base; /* cookie passed into ioremap */
193 /* Paranoia (imagine 64bit kernel overwriting 32bit userspace stack) */
194 uint32_t bbox_reserved[16];
196 static void console_init(void)
198 struct serial_struct sr;
201 s = getenv("CONSOLE");
203 s = getenv("console");
205 int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY);
207 dup2(fd, STDIN_FILENO);
208 dup2(fd, STDOUT_FILENO);
209 xmove_fd(fd, STDERR_FILENO);
211 messageD(L_LOG, "console='%s'", s);
213 /* Make sure fd 0,1,2 are not closed
214 * (so that they won't be used by future opens) */
219 if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) {
220 /* Force the TERM setting to vt102 for serial console
221 * if TERM is set to linux (the default) */
222 if (!s || strcmp(s, "linux") == 0)
223 putenv((char*)"TERM=vt102");
224 if (!ENABLE_FEATURE_INIT_SYSLOG)
227 putenv((char*)"TERM=linux");
230 /* Set terminal settings to reasonable defaults.
231 * NB: careful, we can be called after vfork! */
232 static void set_sane_term(void)
236 tcgetattr(STDIN_FILENO, &tty);
238 /* set control chars */
239 tty.c_cc[VINTR] = 3; /* C-c */
240 tty.c_cc[VQUIT] = 28; /* C-\ */
241 tty.c_cc[VERASE] = 127; /* C-? */
242 tty.c_cc[VKILL] = 21; /* C-u */
243 tty.c_cc[VEOF] = 4; /* C-d */
244 tty.c_cc[VSTART] = 17; /* C-q */
245 tty.c_cc[VSTOP] = 19; /* C-s */
246 tty.c_cc[VSUSP] = 26; /* C-z */
248 /* use line discipline 0 */
251 /* Make it be sane */
252 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
253 tty.c_cflag |= CREAD | HUPCL | CLOCAL;
256 tty.c_iflag = ICRNL | IXON | IXOFF;
259 tty.c_oflag = OPOST | ONLCR;
263 ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
265 tcsetattr(STDIN_FILENO, TCSANOW, &tty);
268 /* Open the new terminal device.
269 * NB: careful, we can be called after vfork! */
270 static void open_stdio_to_tty(const char* tty_name, int exit_on_failure)
272 /* empty tty_name means "use init's tty", else... */
276 /* fd can be only < 0 or 0: */
277 fd = device_open(tty_name, O_RDWR);
279 message(L_LOG | L_CONSOLE, "Can't open %s: %s",
280 tty_name, strerror(errno));
283 if (ENABLE_DEBUG_INIT)
285 /* NB: we don't reach this if we were called after vfork.
286 * Thus halt_reboot_pwoff() itself need not be vfork-safe. */
287 halt_reboot_pwoff(SIGUSR1); /* halt the system */
289 dup2(STDIN_FILENO, STDOUT_FILENO);
290 dup2(STDIN_FILENO, STDERR_FILENO);
295 /* Wrapper around exec:
296 * Takes string (max COMMAND_SIZE chars).
297 * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'.
298 * Otherwise splits words on whitespace, deals with leading dash,
299 * and uses plain exec().
300 * NB: careful, we can be called after vfork!
302 static void init_exec(const char *command)
304 char *cmd[COMMAND_SIZE / 2];
305 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
306 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
308 /* See if any special /bin/sh requiring characters are present */
309 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
310 strcpy(buf, "exec ");
311 strcpy(buf + 5, command + dash); /* excluding "-" */
312 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
313 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
314 cmd[1] = (char*)"-c";
318 /* Convert command (char*) into cmd (char**, one word per string) */
321 next = strcpy(buf, command); /* including "-" */
322 while ((word = strsep(&next, " \t")) != NULL) {
323 if (*word != '\0') { /* not two spaces/tabs together? */
330 /* If we saw leading "-", it is interactive shell.
331 * Try harder to give it a controlling tty.
332 * And skip "-" in actual exec call. */
334 /* _Attempt_ to make stdin a controlling tty. */
335 if (ENABLE_FEATURE_INIT_SCTTY)
336 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
338 BB_EXECVP(cmd[0] + dash, cmd);
339 message(L_LOG | L_CONSOLE, "Cannot run '%s': %s", cmd[0], strerror(errno));
340 /* returns if execvp fails */
343 /* Used only by run_actions */
344 static pid_t run(const struct init_action *a)
347 sigset_t nmask, omask;
349 /* Block sigchild while forking (why?) */
351 sigaddset(&nmask, SIGCHLD);
352 sigprocmask(SIG_BLOCK, &nmask, &omask);
353 if (BB_MMU && (a->action_type & ASKFIRST))
357 sigprocmask(SIG_SETMASK, &omask, NULL);
360 message(L_LOG | L_CONSOLE, "Can't fork");
366 /* Reset signal handlers that were set by the parent process */
379 /* Create a new session and make ourself the process
383 /* Open the new terminal device */
384 open_stdio_to_tty(a->terminal, 1 /* - exit if open fails */);
386 // NB: do not enable unless you change vfork to fork above
387 #ifdef BUT_RUN_ACTIONS_ALREADY_DOES_WAITING
388 /* If the init Action requires us to wait, then force the
389 * supplied terminal to be the controlling tty. */
390 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
391 /* Now fork off another process to just hang around */
394 message(L_LOG | L_CONSOLE, "Can't fork");
399 /* Parent - wait till the child is done */
405 signal(SIGCHLD, SIG_DFL);
408 /* See if stealing the controlling tty back is necessary */
409 if (tcgetpgrp(0) != getpid())
412 /* Use a temporary process to steal the controlling tty. */
415 message(L_LOG | L_CONSOLE, "Can't fork");
420 ioctl(0, TIOCSCTTY, 1);
426 /* Child - fall though to actually execute things */
430 /* NB: on NOMMU we can't wait for input in child, so
431 * "askfirst" will work the same as "respawn". */
432 if (BB_MMU && (a->action_type & ASKFIRST)) {
433 static const char press_enter[] ALIGN1 =
434 #ifdef CUSTOMIZED_BANNER
435 #include CUSTOMIZED_BANNER
437 "\nPlease press Enter to activate this console. ";
440 * Save memory by not exec-ing anything large (like a shell)
441 * before the user wants it. This is critical if swap is not
442 * enabled and the system has low memory. Generally this will
443 * be run on the second virtual console, and the first will
444 * be allowed to start a shell or whatever an init script
447 messageD(L_LOG, "waiting for enter to start '%s'"
448 "(pid %d, tty '%s')\n",
449 a->command, getpid(), a->terminal);
450 full_write(STDOUT_FILENO, press_enter, sizeof(press_enter) - 1);
451 while (safe_read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
455 if (ENABLE_FEATURE_INIT_COREDUMPS) {
457 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
459 limit.rlim_cur = RLIM_INFINITY;
460 limit.rlim_max = RLIM_INFINITY;
461 setrlimit(RLIMIT_CORE, &limit);
465 /* Log the process name and args */
466 message(L_LOG, "starting pid %d, tty '%s': '%s'",
467 getpid(), a->terminal, a->command);
469 /* Now run it. The new program will take over this PID,
470 * so nothing further in init.c should be run. */
471 init_exec(a->command);
472 /* We're still here? Some error happened. */
476 static void delete_init_action(struct init_action *action)
478 struct init_action *a, *b = NULL;
480 for (a = init_action_list; a; b = a, a = a->next) {
483 init_action_list = a->next;
493 /* Run all commands of a particular type */
494 static void run_actions(int action_type)
496 struct init_action *a, *tmp;
498 for (a = init_action_list; a; a = tmp) {
500 if (a->action_type & action_type) {
501 // Pointless: run() will error out if open of device fails.
502 ///* a->terminal of "" means "init's console" */
503 //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
504 // //message(L_LOG | L_CONSOLE, "Device %s cannot be opened in RW mode", a->terminal /*, strerror(errno)*/);
505 // delete_init_action(a);
507 if (a->action_type & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
509 delete_init_action(a);
510 } else if (a->action_type & ONCE) {
512 delete_init_action(a);
513 } else if (a->action_type & (RESPAWN | ASKFIRST)) {
514 /* Only run stuff with pid==0. If they have
515 * a pid, that means it is still running */
524 static void init_reboot(unsigned long magic)
527 /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in
528 * linux/kernel/sys.c, which can cause the machine to panic when
529 * the init process is killed.... */
531 if (pid == 0) { /* child */
538 static void kill_all_processes(void)
540 /* run everything to be run at "shutdown". This is done _prior_
541 * to killing everything, in case people wish to use scripts to
542 * shut things down gracefully... */
543 run_actions(SHUTDOWN);
545 /* first disable all our signals */
546 sigprocmask_allsigs(SIG_BLOCK);
548 message(L_CONSOLE | L_LOG, "The system is going down NOW!");
550 /* Allow Ctrl-Alt-Del to reboot system. */
551 init_reboot(RB_ENABLE_CAD);
553 /* Send signals to every process _except_ pid 1 */
554 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM");
559 message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "KILL");
565 static void halt_reboot_pwoff(int sig)
567 const char *m = "halt";
570 kill_all_processes();
573 if (sig == SIGTERM) {
576 } else if (sig == SIGUSR2) {
580 message(L_CONSOLE | L_LOG, "Requesting system %s", m);
581 /* allow time for last message to reach serial console */
587 /* Handler for QUIT - exec "restart" action,
588 * else (no such action defined) do nothing */
589 static void exec_restart_action(int sig UNUSED_PARAM)
591 struct init_action *a;
593 for (a = init_action_list; a; a = a->next) {
594 if (a->action_type & RESTART) {
595 kill_all_processes();
597 /* unblock all signals (blocked in kill_all_processes()) */
598 sigprocmask_allsigs(SIG_UNBLOCK);
600 /* Open the new terminal device */
601 open_stdio_to_tty(a->terminal, 0 /* - halt if open fails */);
603 messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command);
604 init_exec(a->command);
606 init_reboot(RB_HALT_SYSTEM);
612 static void ctrlaltdel_signal(int sig UNUSED_PARAM)
614 run_actions(CTRLALTDEL);
617 /* The SIGSTOP & SIGTSTP handler */
618 static void stop_handler(int sig UNUSED_PARAM)
620 int saved_errno = errno;
629 /* The SIGCONT handler */
630 static void cont_handler(int sig UNUSED_PARAM)
635 static void new_init_action(uint8_t action_type, const char *command, const char *cons)
637 struct init_action *a, *last;
640 // if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
643 /* Append to the end of the list */
644 for (a = last = init_action_list; a; a = a->next) {
645 /* don't enter action if it's already in the list,
646 * but do overwrite existing actions */
647 if ((strcmp(a->command, command) == 0)
648 && (strcmp(a->terminal, cons) == 0)) {
649 a->action_type = action_type;
655 a = xzalloc(sizeof(*a));
659 init_action_list = a;
661 a->action_type = action_type;
662 safe_strncpy(a->command, command, sizeof(a->command));
663 safe_strncpy(a->terminal, cons, sizeof(a->terminal));
664 messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
665 a->command, a->action_type, a->terminal);
668 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
669 * then parse_inittab() simply adds in some default
670 * actions(i.e., runs INIT_SCRIPT and then starts a pair
671 * of "askfirst" shells). If CONFIG_FEATURE_USE_INITTAB
672 * _is_ defined, but /etc/inittab is missing, this
673 * results in the same set of default behaviors.
675 static void parse_inittab(void)
678 /* order must correspond to SYSINIT..RESTART constants */
679 static const char actions[] ALIGN1 =
680 "sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
681 "ctrlaltdel\0""shutdown\0""restart\0";
683 parser_t *parser = config_open(INITTAB);
684 /* No inittab file -- set up some default behavior */
685 if (parser == NULL) {
686 /* Reboot on Ctrl-Alt-Del */
687 new_init_action(CTRLALTDEL, "reboot", "");
688 /* Umount all filesystems on halt/reboot */
689 new_init_action(SHUTDOWN, "umount -a -r", "");
690 /* Swapoff on halt/reboot */
691 if (ENABLE_SWAPONOFF)
692 new_init_action(SHUTDOWN, "swapoff -a", "");
693 /* Prepare to restart init when a QUIT is received */
694 new_init_action(RESTART, "init", "");
695 /* Askfirst shell on tty1-4 */
696 new_init_action(ASKFIRST, bb_default_login_shell, "");
697 //TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
698 new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
699 new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
700 new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
702 new_init_action(SYSINIT, INIT_SCRIPT, "");
706 /* optional_tty:ignored_runlevel:action:command
707 * Delims are not to be collapsed and need exactly 4 tokens
709 while (config_read(parser, token, 4, 0, "#:", PARSE_DONT_TRIM|PARSE_DONT_REDUCE|PARSE_LAST_IS_GREEDY)) {
711 char *tty = token[0];
713 if (!token[3]) /* less than 4 tokens */
715 action = index_in_strings(actions, token[2]);
716 if (action < 0 || !token[3][0]) /* token[3]: command */
718 /* turn .*TTY -> /dev/TTY */
720 if (strncmp(tty, "/dev/", 5) == 0)
722 tty = concat_path_file("/dev/", tty);
724 new_init_action(1 << action, token[3], tty);
729 message(L_LOG | L_CONSOLE, "Bad inittab entry at line %d",
732 config_close(parser);
735 #if ENABLE_FEATURE_USE_INITTAB
736 static void reload_signal(int sig UNUSED_PARAM)
738 struct init_action *a, *tmp;
740 message(L_LOG, "reloading /etc/inittab");
742 /* disable old entrys */
743 for (a = init_action_list; a; a = a->next) {
744 a->action_type = ONCE;
749 if (ENABLE_FEATURE_KILL_REMOVED) {
750 /* Be nice and send SIGTERM first */
751 for (a = init_action_list; a; a = a->next) {
753 if ((a->action_type & ONCE) && pid != 0) {
757 #if CONFIG_FEATURE_KILL_DELAY
758 /* NB: parent will wait in NOMMU case */
759 if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
760 sleep(CONFIG_FEATURE_KILL_DELAY);
761 for (a = init_action_list; a; a = a->next) {
763 if ((a->action_type & ONCE) && pid != 0) {
772 /* remove unused entrys */
773 for (a = init_action_list; a; a = tmp) {
775 if ((a->action_type & (ONCE | SYSINIT | WAIT)) && a->pid == 0) {
776 delete_init_action(a);
779 run_actions(RESPAWN | ASKFIRST);
783 int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
784 int init_main(int argc UNUSED_PARAM, char **argv)
786 struct init_action *a;
789 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
791 if (argv[1] && !strcmp(argv[1], "-q")) {
792 return kill(1, SIGHUP);
795 if (!ENABLE_DEBUG_INIT) {
796 /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
798 && (!ENABLE_FEATURE_INITRD || !strstr(applet_name, "linuxrc"))
802 /* Set up sig handlers -- be sure to
803 * clear all of these in run() */
804 signal(SIGQUIT, exec_restart_action);
806 + (1 << SIGUSR1) /* halt */
807 + (1 << SIGUSR2) /* poweroff */
808 + (1 << SIGTERM) /* reboot */
809 , halt_reboot_pwoff);
810 signal(SIGINT, ctrlaltdel_signal);
811 signal(SIGCONT, cont_handler);
817 /* Turn off rebooting via CTL-ALT-DEL -- we get a
818 * SIGINT on CAD so we can shut things down gracefully... */
819 init_reboot(RB_DISABLE_CAD);
822 /* Figure out where the default console should be */
828 const char *const *e;
829 /* Make sure environs is set to something sane */
830 for (e = environment; *e; e++)
835 setenv("RUNLEVEL", argv[1], 1);
838 message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);
840 /* Make sure there is enough memory to do something useful. */
841 if (ENABLE_SWAPONOFF) {
844 if (!sysinfo(&info) &&
845 (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024)
847 message(L_CONSOLE, "Low memory, forcing swapon");
848 /* swapon -a requires /proc typically */
849 new_init_action(SYSINIT, "mount -t proc proc /proc", "");
850 /* Try to turn on swap */
851 new_init_action(SYSINIT, "swapon -a", "");
852 run_actions(SYSINIT); /* wait and removing */
856 /* Check if we are supposed to be in single user mode */
858 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
860 /* ??? shouldn't we set RUNLEVEL="b" here? */
861 /* Start a shell on console */
862 new_init_action(RESPAWN, bb_default_login_shell, "");
864 /* Not in single user mode -- see what inittab says */
866 /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
867 * then parse_inittab() simply adds in some default
868 * actions(i.e., runs INIT_SCRIPT and then starts a pair
869 * of "askfirst" shells */
874 if (getenv("SELINUX_INIT") == NULL) {
877 putenv((char*)"SELINUX_INIT=YES");
878 if (selinux_init_load_policy(&enforce) == 0) {
879 BB_EXECVP(argv[0], argv);
880 } else if (enforce > 0) {
881 /* SELinux in enforcing mode but load_policy failed */
882 message(L_CONSOLE, "Cannot load SELinux Policy. "
883 "Machine is in enforcing mode. Halting now.");
887 #endif /* CONFIG_SELINUX */
889 /* Make the command line just say "init" - thats all, nothing else */
890 strncpy(argv[0], "init", strlen(argv[0]));
891 /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
893 memset(*argv, 0, strlen(*argv));
895 /* Now run everything that needs to be run */
897 /* First run the sysinit command */
898 run_actions(SYSINIT);
900 /* Next run anything that wants to block */
903 /* Next run anything to be run only once */
906 /* Redefine SIGHUP to reread /etc/inittab */
907 #if ENABLE_FEATURE_USE_INITTAB
908 signal(SIGHUP, reload_signal);
910 signal(SIGHUP, SIG_IGN);
913 /* Now run the looping stuff for the rest of forever */
915 /* run the respawn/askfirst stuff */
916 run_actions(RESPAWN | ASKFIRST);
918 /* Don't consume all CPU time -- sleep a bit */
921 /* Wait for any child process to exit */
924 /* Find out who died and clean up their corpse */
925 for (a = init_action_list; a; a = a->next) {
926 if (a->pid == wpid) {
927 /* Set the pid to 0 so that the process gets
928 * restarted by run_actions() */
930 message(L_LOG, "process '%s' (pid %d) exited. "
931 "Scheduling for restart.",
935 /* see if anyone else is waiting to be reaped */
936 wpid = wait_any_nohang(NULL);