aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-01-31 01:02:07 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-01-31 01:02:07 +0000
commitcab28aa7de336b0a39ef43ce0eb035a2cab30d4d (patch)
tree1f42544e65cd60dea87e631942506f1a5b206823 /init
parent6c62246a3598efd3d1e9264f8d9f44d8d93a6453 (diff)
downloadbusybox-w32-cab28aa7de336b0a39ef43ce0eb035a2cab30d4d.tar.gz
busybox-w32-cab28aa7de336b0a39ef43ce0eb035a2cab30d4d.tar.bz2
busybox-w32-cab28aa7de336b0a39ef43ce0eb035a2cab30d4d.zip
init: preparatory patch, no code changes
Diffstat (limited to 'init')
-rw-r--r--init/init.c44
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
66static void halt_reboot_pwoff(int sig) NORETURN; 66static void halt_reboot_pwoff(int sig) NORETURN;
67 67
68static 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
80static void loop_forever(void) NORETURN; 68static void loop_forever(void) NORETURN;
81static void loop_forever(void) 69static 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
467static 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 */
480static void run_actions(int action_type) 480static 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
510static void init_reboot(unsigned long magic) 510static 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 */
575static void exec_restart_action(int sig UNUSED_PARAM) 575static 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
726static void reload_signal(int sig UNUSED_PARAM) 726static 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
772void reload_signal(int sig); 772void reload_inittab(int sig);
773#endif 773#endif
774 774
775int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 775int 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) {