diff options
Diffstat (limited to 'busybox/init/init.c')
-rw-r--r-- | busybox/init/init.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/busybox/init/init.c b/busybox/init/init.c index 0c8dc89dc..8687b106c 100644 --- a/busybox/init/init.c +++ b/busybox/init/init.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <limits.h> | 39 | #include <limits.h> |
40 | #include <sys/fcntl.h> | 40 | #include <sys/fcntl.h> |
41 | #include <sys/ioctl.h> | 41 | #include <sys/ioctl.h> |
42 | #include <sys/mount.h> | ||
43 | #include <sys/types.h> | 42 | #include <sys/types.h> |
44 | #include <sys/wait.h> | 43 | #include <sys/wait.h> |
45 | #include <sys/reboot.h> | 44 | #include <sys/reboot.h> |
@@ -156,7 +155,7 @@ static struct init_action *init_action_list = NULL; | |||
156 | static char console[CONSOLE_BUFF_SIZE] = _PATH_CONSOLE; | 155 | static char console[CONSOLE_BUFF_SIZE] = _PATH_CONSOLE; |
157 | 156 | ||
158 | #ifndef CONFIG_SYSLOGD | 157 | #ifndef CONFIG_SYSLOGD |
159 | static char *log = VC_5; | 158 | static char *log_console = VC_5; |
160 | #endif | 159 | #endif |
161 | static sig_atomic_t got_cont = 0; | 160 | static sig_atomic_t got_cont = 0; |
162 | static const int LOG = 0x1; | 161 | static const int LOG = 0x1; |
@@ -239,9 +238,9 @@ static void message(int device, const char *fmt, ...) | |||
239 | /* Take full control of the log tty, and never close it. | 238 | /* Take full control of the log tty, and never close it. |
240 | * It's mine, all mine! Muhahahaha! */ | 239 | * It's mine, all mine! Muhahahaha! */ |
241 | if (log_fd < 0) { | 240 | if (log_fd < 0) { |
242 | if ((log_fd = device_open(log, O_RDWR | O_NDELAY | O_NOCTTY)) < 0) { | 241 | if ((log_fd = device_open(log_console, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) { |
243 | log_fd = -2; | 242 | log_fd = -2; |
244 | bb_error_msg("Bummer, can't write to log on %s!", log); | 243 | bb_error_msg("Bummer, can't write to log on %s!", log_console); |
245 | device = CONSOLE; | 244 | device = CONSOLE; |
246 | } else { | 245 | } else { |
247 | fcntl(log_fd, F_SETFD, FD_CLOEXEC); | 246 | fcntl(log_fd, F_SETFD, FD_CLOEXEC); |
@@ -254,7 +253,7 @@ static void message(int device, const char *fmt, ...) | |||
254 | 253 | ||
255 | if (device & CONSOLE) { | 254 | if (device & CONSOLE) { |
256 | int fd = device_open(_PATH_CONSOLE, | 255 | int fd = device_open(_PATH_CONSOLE, |
257 | O_WRONLY | O_NOCTTY | O_NDELAY); | 256 | O_WRONLY | O_NOCTTY | O_NONBLOCK); |
258 | /* Always send console messages to /dev/console so people will see them. */ | 257 | /* Always send console messages to /dev/console so people will see them. */ |
259 | if (fd >= 0) { | 258 | if (fd >= 0) { |
260 | bb_full_write(fd, msg, l); | 259 | bb_full_write(fd, msg, l); |
@@ -309,6 +308,7 @@ static void set_term(int fd) | |||
309 | tcsetattr(fd, TCSANOW, &tty); | 308 | tcsetattr(fd, TCSANOW, &tty); |
310 | } | 309 | } |
311 | 310 | ||
311 | #ifdef CONFIG_FEATURE_INIT_SWAPON | ||
312 | /* How much memory does this machine have? | 312 | /* How much memory does this machine have? |
313 | Units are kBytes to avoid overflow on 4GB machines */ | 313 | Units are kBytes to avoid overflow on 4GB machines */ |
314 | static unsigned int check_free_memory(void) | 314 | static unsigned int check_free_memory(void) |
@@ -337,6 +337,7 @@ static unsigned int check_free_memory(void) | |||
337 | return(result * u); | 337 | return(result * u); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | #endif /* CONFIG_FEATURE_INIT_SWAPON */ | ||
340 | 341 | ||
341 | static void console_init(void) | 342 | static void console_init(void) |
342 | { | 343 | { |
@@ -381,7 +382,7 @@ static void console_init(void) | |||
381 | if (fd < 0) { | 382 | if (fd < 0) { |
382 | /* Perhaps we should panic here? */ | 383 | /* Perhaps we should panic here? */ |
383 | #ifndef CONFIG_SYSLOGD | 384 | #ifndef CONFIG_SYSLOGD |
384 | log = | 385 | log_console = |
385 | #endif | 386 | #endif |
386 | safe_strncpy(console, "/dev/null", sizeof(console)); | 387 | safe_strncpy(console, "/dev/null", sizeof(console)); |
387 | } else { | 388 | } else { |
@@ -393,7 +394,7 @@ static void console_init(void) | |||
393 | if (s == NULL || strcmp(s, "linux") == 0) | 394 | if (s == NULL || strcmp(s, "linux") == 0) |
394 | putenv("TERM=vt102"); | 395 | putenv("TERM=vt102"); |
395 | #ifndef CONFIG_SYSLOGD | 396 | #ifndef CONFIG_SYSLOGD |
396 | log = console; | 397 | log_console = console; |
397 | #endif | 398 | #endif |
398 | } else { | 399 | } else { |
399 | if (s == NULL) | 400 | if (s == NULL) |
@@ -423,9 +424,8 @@ static void fixup_argv(int argc, char **argv, char *new_argv0) | |||
423 | 424 | ||
424 | static pid_t run(const struct init_action *a) | 425 | static pid_t run(const struct init_action *a) |
425 | { | 426 | { |
426 | struct stat sb; | ||
427 | int i, junk; | 427 | int i, junk; |
428 | pid_t pid, pgrp, tmp_pid; | 428 | pid_t pid; |
429 | char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath; | 429 | char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath; |
430 | char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */ | 430 | char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */ |
431 | sigset_t nmask, omask; | 431 | sigset_t nmask, omask; |
@@ -441,6 +441,8 @@ static pid_t run(const struct init_action *a) | |||
441 | sigprocmask(SIG_BLOCK, &nmask, &omask); | 441 | sigprocmask(SIG_BLOCK, &nmask, &omask); |
442 | 442 | ||
443 | if ((pid = fork()) == 0) { | 443 | if ((pid = fork()) == 0) { |
444 | struct stat sb; | ||
445 | |||
444 | /* Clean up */ | 446 | /* Clean up */ |
445 | close(0); | 447 | close(0); |
446 | close(1); | 448 | close(1); |
@@ -453,6 +455,7 @@ static pid_t run(const struct init_action *a) | |||
453 | signal(SIGINT, SIG_DFL); | 455 | signal(SIGINT, SIG_DFL); |
454 | signal(SIGTERM, SIG_DFL); | 456 | signal(SIGTERM, SIG_DFL); |
455 | signal(SIGHUP, SIG_DFL); | 457 | signal(SIGHUP, SIG_DFL); |
458 | signal(SIGQUIT, SIG_DFL); | ||
456 | signal(SIGCONT, SIG_DFL); | 459 | signal(SIGCONT, SIG_DFL); |
457 | signal(SIGSTOP, SIG_DFL); | 460 | signal(SIGSTOP, SIG_DFL); |
458 | signal(SIGTSTP, SIG_DFL); | 461 | signal(SIGTSTP, SIG_DFL); |
@@ -464,11 +467,10 @@ static pid_t run(const struct init_action *a) | |||
464 | /* Open the new terminal device */ | 467 | /* Open the new terminal device */ |
465 | if ((device_open(a->terminal, O_RDWR)) < 0) { | 468 | if ((device_open(a->terminal, O_RDWR)) < 0) { |
466 | if (stat(a->terminal, &sb) != 0) { | 469 | if (stat(a->terminal, &sb) != 0) { |
467 | message(LOG | CONSOLE, "device '%s' does not exist.", | 470 | message(LOG | CONSOLE, "device '%s' does not exist.", a->terminal); |
468 | a->terminal); | 471 | } else { |
469 | _exit(1); | 472 | message(LOG | CONSOLE, "Bummer, can't open %s", a->terminal); |
470 | } | 473 | } |
471 | message(LOG | CONSOLE, "Bummer, can't open %s", a->terminal); | ||
472 | _exit(1); | 474 | _exit(1); |
473 | } | 475 | } |
474 | 476 | ||
@@ -482,6 +484,7 @@ static pid_t run(const struct init_action *a) | |||
482 | /* If the init Action requires us to wait, then force the | 484 | /* If the init Action requires us to wait, then force the |
483 | * supplied terminal to be the controlling tty. */ | 485 | * supplied terminal to be the controlling tty. */ |
484 | if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) { | 486 | if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) { |
487 | pid_t pgrp, tmp_pid; | ||
485 | 488 | ||
486 | /* Now fork off another process to just hang around */ | 489 | /* Now fork off another process to just hang around */ |
487 | if ((pid = fork()) < 0) { | 490 | if ((pid = fork()) < 0) { |
@@ -693,6 +696,7 @@ static void shutdown_system(void) | |||
693 | /* first disable all our signals */ | 696 | /* first disable all our signals */ |
694 | sigemptyset(&block_signals); | 697 | sigemptyset(&block_signals); |
695 | sigaddset(&block_signals, SIGHUP); | 698 | sigaddset(&block_signals, SIGHUP); |
699 | sigaddset(&block_signals, SIGQUIT); | ||
696 | sigaddset(&block_signals, SIGCHLD); | 700 | sigaddset(&block_signals, SIGCHLD); |
697 | sigaddset(&block_signals, SIGUSR1); | 701 | sigaddset(&block_signals, SIGUSR1); |
698 | sigaddset(&block_signals, SIGUSR2); | 702 | sigaddset(&block_signals, SIGUSR2); |
@@ -730,13 +734,12 @@ static void exec_signal(int sig) | |||
730 | for (a = init_action_list; a; a = tmp) { | 734 | for (a = init_action_list; a; a = tmp) { |
731 | tmp = a->next; | 735 | tmp = a->next; |
732 | if (a->action & RESTART) { | 736 | if (a->action & RESTART) { |
733 | struct stat sb; | ||
734 | |||
735 | shutdown_system(); | 737 | shutdown_system(); |
736 | 738 | ||
737 | /* unblock all signals, blocked in shutdown_system() */ | 739 | /* unblock all signals, blocked in shutdown_system() */ |
738 | sigemptyset(&unblock_signals); | 740 | sigemptyset(&unblock_signals); |
739 | sigaddset(&unblock_signals, SIGHUP); | 741 | sigaddset(&unblock_signals, SIGHUP); |
742 | sigaddset(&unblock_signals, SIGQUIT); | ||
740 | sigaddset(&unblock_signals, SIGCHLD); | 743 | sigaddset(&unblock_signals, SIGCHLD); |
741 | sigaddset(&unblock_signals, SIGUSR1); | 744 | sigaddset(&unblock_signals, SIGUSR1); |
742 | sigaddset(&unblock_signals, SIGUSR2); | 745 | sigaddset(&unblock_signals, SIGUSR2); |
@@ -754,6 +757,7 @@ static void exec_signal(int sig) | |||
754 | 757 | ||
755 | /* Open the new terminal device */ | 758 | /* Open the new terminal device */ |
756 | if ((device_open(a->terminal, O_RDWR)) < 0) { | 759 | if ((device_open(a->terminal, O_RDWR)) < 0) { |
760 | struct stat sb; | ||
757 | if (stat(a->terminal, &sb) != 0) { | 761 | if (stat(a->terminal, &sb) != 0) { |
758 | message(LOG | CONSOLE, "device '%s' does not exist.", a->terminal); | 762 | message(LOG | CONSOLE, "device '%s' does not exist.", a->terminal); |
759 | } else { | 763 | } else { |
@@ -907,6 +911,7 @@ static void delete_init_action(struct init_action *action) | |||
907 | } | 911 | } |
908 | } | 912 | } |
909 | 913 | ||
914 | #ifdef CONFIG_FEATURE_INIT_SWAPON | ||
910 | /* Make sure there is enough memory to do something useful. * | 915 | /* Make sure there is enough memory to do something useful. * |
911 | * Calls "swapon -a" if needed so be sure /etc/fstab is present... */ | 916 | * Calls "swapon -a" if needed so be sure /etc/fstab is present... */ |
912 | static void check_memory(void) | 917 | static void check_memory(void) |
@@ -934,6 +939,9 @@ static void check_memory(void) | |||
934 | message(CONSOLE, "Sorry, your computer does not have enough memory."); | 939 | message(CONSOLE, "Sorry, your computer does not have enough memory."); |
935 | loop_forever(); | 940 | loop_forever(); |
936 | } | 941 | } |
942 | #else | ||
943 | # define check_memory() | ||
944 | #endif /* CONFIG_FEATURE_INIT_SWAPON */ | ||
937 | 945 | ||
938 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, | 946 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, |
939 | * then parse_inittab() simply adds in some default | 947 | * then parse_inittab() simply adds in some default |
@@ -1097,6 +1105,7 @@ extern int init_main(int argc, char **argv) | |||
1097 | /* Set up sig handlers -- be sure to | 1105 | /* Set up sig handlers -- be sure to |
1098 | * clear all of these in run() */ | 1106 | * clear all of these in run() */ |
1099 | signal(SIGHUP, exec_signal); | 1107 | signal(SIGHUP, exec_signal); |
1108 | signal(SIGQUIT, exec_signal); | ||
1100 | signal(SIGUSR1, halt_signal); | 1109 | signal(SIGUSR1, halt_signal); |
1101 | signal(SIGUSR2, halt_signal); | 1110 | signal(SIGUSR2, halt_signal); |
1102 | signal(SIGINT, ctrlaltdel_signal); | 1111 | signal(SIGINT, ctrlaltdel_signal); |