diff options
Diffstat (limited to 'init')
| -rw-r--r-- | init/init.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/init/init.c b/init/init.c index cea30c99f..6af6830e4 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -65,18 +65,6 @@ enum { | |||
| 65 | 65 | ||
| 66 | static void halt_reboot_pwoff(int sig) NORETURN; | 66 | static void halt_reboot_pwoff(int sig) NORETURN; |
| 67 | 67 | ||
| 68 | static void waitfor(pid_t pid) | ||
| 69 | { | ||
| 70 | /* waitfor(run(x)): protect against failed fork inside run() */ | ||
| 71 | if (pid <= 0) | ||
| 72 | return; | ||
| 73 | |||
| 74 | /* Wait for any child (prevent zombies from exiting orphaned processes) | ||
| 75 | * but exit the loop only when specified one has exited. */ | ||
| 76 | while (wait(NULL) != pid) | ||
| 77 | continue; | ||
| 78 | } | ||
| 79 | |||
| 80 | static void loop_forever(void) NORETURN; | 68 | static void loop_forever(void) NORETURN; |
| 81 | static void loop_forever(void) | 69 | static void loop_forever(void) |
| 82 | { | 70 | { |
| @@ -476,6 +464,18 @@ static void delete_init_action(struct init_action *action) | |||
| 476 | } | 464 | } |
| 477 | } | 465 | } |
| 478 | 466 | ||
| 467 | static void waitfor(pid_t pid) | ||
| 468 | { | ||
| 469 | /* waitfor(run(x)): protect against failed fork inside run() */ | ||
| 470 | if (pid <= 0) | ||
| 471 | return; | ||
| 472 | |||
| 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) | ||
| 476 | continue; | ||
| 477 | } | ||
| 478 | |||
| 479 | /* Run all commands of a particular type */ | 479 | /* Run all commands of a particular type */ |
| 480 | static void run_actions(int action_type) | 480 | static void run_actions(int action_type) |
| 481 | { | 481 | { |
| @@ -507,7 +507,7 @@ static void run_actions(int action_type) | |||
| 507 | } | 507 | } |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | static void init_reboot(unsigned long magic) | 510 | static void low_level_reboot(unsigned long magic) |
| 511 | { | 511 | { |
| 512 | pid_t pid; | 512 | pid_t pid; |
| 513 | /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in | 513 | /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) in |
| @@ -534,7 +534,7 @@ static void kill_all_processes(void) | |||
| 534 | message(L_CONSOLE | L_LOG, "The system is going down NOW!"); | 534 | message(L_CONSOLE | L_LOG, "The system is going down NOW!"); |
| 535 | 535 | ||
| 536 | /* Allow Ctrl-Alt-Del to reboot system. */ | 536 | /* Allow Ctrl-Alt-Del to reboot system. */ |
| 537 | init_reboot(RB_ENABLE_CAD); | 537 | low_level_reboot(RB_ENABLE_CAD); |
| 538 | 538 | ||
| 539 | /* Send signals to every process _except_ pid 1 */ | 539 | /* Send signals to every process _except_ pid 1 */ |
| 540 | message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM"); | 540 | message(L_CONSOLE | L_LOG, "Sending SIG%s to all processes", "TERM"); |
| @@ -566,13 +566,13 @@ static void halt_reboot_pwoff(int sig) | |||
| 566 | message(L_CONSOLE | L_LOG, "Requesting system %s", m); | 566 | message(L_CONSOLE | L_LOG, "Requesting system %s", m); |
| 567 | /* allow time for last message to reach serial console */ | 567 | /* allow time for last message to reach serial console */ |
| 568 | sleep(2); | 568 | sleep(2); |
| 569 | init_reboot(rb); | 569 | low_level_reboot(rb); |
| 570 | loop_forever(); | 570 | loop_forever(); |
| 571 | } | 571 | } |
| 572 | 572 | ||
| 573 | /* Handler for QUIT - exec "restart" action, | 573 | /* Handler for QUIT - exec "restart" action, |
| 574 | * else (no such action defined) do nothing */ | 574 | * else (no such action defined) do nothing */ |
| 575 | static void exec_restart_action(int sig UNUSED_PARAM) | 575 | static void restart_handler(int sig UNUSED_PARAM) |
| 576 | { | 576 | { |
| 577 | struct init_action *a; | 577 | struct init_action *a; |
| 578 | 578 | ||
| @@ -589,7 +589,7 @@ static void exec_restart_action(int sig UNUSED_PARAM) | |||
| 589 | messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command); | 589 | messageD(L_CONSOLE | L_LOG, "Trying to re-exec %s", a->command); |
| 590 | init_exec(a->command); | 590 | init_exec(a->command); |
| 591 | sleep(2); | 591 | sleep(2); |
| 592 | init_reboot(RB_HALT_SYSTEM); | 592 | low_level_reboot(RB_HALT_SYSTEM); |
| 593 | loop_forever(); | 593 | loop_forever(); |
| 594 | } | 594 | } |
| 595 | } | 595 | } |
| @@ -723,7 +723,7 @@ static void parse_inittab(void) | |||
| 723 | } | 723 | } |
| 724 | 724 | ||
| 725 | #if ENABLE_FEATURE_USE_INITTAB | 725 | #if ENABLE_FEATURE_USE_INITTAB |
| 726 | static void reload_signal(int sig UNUSED_PARAM) | 726 | static void reload_inittab(int sig UNUSED_PARAM) |
| 727 | { | 727 | { |
| 728 | struct init_action *a, *tmp; | 728 | struct init_action *a, *tmp; |
| 729 | 729 | ||
| @@ -769,7 +769,7 @@ static void reload_signal(int sig UNUSED_PARAM) | |||
| 769 | run_actions(RESPAWN | ASKFIRST); | 769 | run_actions(RESPAWN | ASKFIRST); |
| 770 | } | 770 | } |
| 771 | #else | 771 | #else |
| 772 | void reload_signal(int sig); | 772 | void reload_inittab(int sig); |
| 773 | #endif | 773 | #endif |
| 774 | 774 | ||
| 775 | int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 775 | int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| @@ -797,7 +797,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
| 797 | // Move signal handling from handlers to main loop - | 797 | // Move signal handling from handlers to main loop - |
| 798 | // we have bad races otherwise. | 798 | // we have bad races otherwise. |
| 799 | // E.g. parse_inittab() vs. delete_init_action()... | 799 | // E.g. parse_inittab() vs. delete_init_action()... |
| 800 | signal(SIGQUIT, exec_restart_action); | 800 | signal(SIGQUIT, restart_handler); |
| 801 | bb_signals(0 | 801 | bb_signals(0 |
| 802 | + (1 << SIGUSR1) /* halt */ | 802 | + (1 << SIGUSR1) /* halt */ |
| 803 | + (1 << SIGUSR2) /* poweroff */ | 803 | + (1 << SIGUSR2) /* poweroff */ |
| @@ -812,7 +812,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
| 812 | 812 | ||
| 813 | /* Turn off rebooting via CTL-ALT-DEL -- we get a | 813 | /* Turn off rebooting via CTL-ALT-DEL -- we get a |
| 814 | * SIGINT on CAD so we can shut things down gracefully... */ | 814 | * SIGINT on CAD so we can shut things down gracefully... */ |
| 815 | init_reboot(RB_DISABLE_CAD); | 815 | low_level_reboot(RB_DISABLE_CAD); |
| 816 | } | 816 | } |
| 817 | 817 | ||
| 818 | /* Figure out where the default console should be */ | 818 | /* Figure out where the default console should be */ |
| @@ -900,7 +900,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
| 900 | run_actions(ONCE); | 900 | run_actions(ONCE); |
| 901 | 901 | ||
| 902 | /* Redefine SIGHUP to reread /etc/inittab */ | 902 | /* Redefine SIGHUP to reread /etc/inittab */ |
| 903 | signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_signal : SIG_IGN); | 903 | signal(SIGHUP, ENABLE_FEATURE_USE_INITTAB ? reload_inittab : SIG_IGN); |
| 904 | 904 | ||
| 905 | /* Now run the looping stuff for the rest of forever */ | 905 | /* Now run the looping stuff for the rest of forever */ |
| 906 | while (1) { | 906 | while (1) { |
