aboutsummaryrefslogtreecommitdiff
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
parent6c62246a3598efd3d1e9264f8d9f44d8d93a6453 (diff)
downloadbusybox-w32-cab28aa7de336b0a39ef43ce0eb035a2cab30d4d.tar.gz
busybox-w32-cab28aa7de336b0a39ef43ce0eb035a2cab30d4d.tar.bz2
busybox-w32-cab28aa7de336b0a39ef43ce0eb035a2cab30d4d.zip
init: preparatory patch, no code changes
-rw-r--r--include/libbb.h4
-rw-r--r--init/init.c44
-rw-r--r--libbb/signals.c2
-rw-r--r--runit/runsv.c4
-rw-r--r--runit/svlogd.c8
5 files changed, 31 insertions, 31 deletions
diff --git a/include/libbb.h b/include/libbb.h
index e1a6d120b..0403281c6 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -353,8 +353,8 @@ enum {
353void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; 353void bb_signals(int sigs, void (*f)(int)) FAST_FUNC;
354/* Unlike signal() and bb_signals, sets handler with sigaction() 354/* Unlike signal() and bb_signals, sets handler with sigaction()
355 * and in a way that while signal handler is run, no other signals 355 * and in a way that while signal handler is run, no other signals
356 * will be blocked: */ 356 * will be blocked; syscalls will not be restarted: */
357void bb_signals_recursive(int sigs, void (*f)(int)) FAST_FUNC; 357void bb_signals_recursive_norestart(int sigs, void (*f)(int)) FAST_FUNC;
358/* syscalls like read() will be interrupted with EINTR: */ 358/* syscalls like read() will be interrupted with EINTR: */
359void signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int)) FAST_FUNC; 359void signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int)) FAST_FUNC;
360/* syscalls like read() won't be interrupted (though select/poll will be): */ 360/* syscalls like read() won't be interrupted (though select/poll will be): */
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) {
diff --git a/libbb/signals.c b/libbb/signals.c
index f56ce65a8..a528756ff 100644
--- a/libbb/signals.c
+++ b/libbb/signals.c
@@ -47,7 +47,7 @@ void FAST_FUNC bb_signals(int sigs, void (*f)(int))
47 } 47 }
48} 48}
49 49
50void FAST_FUNC bb_signals_recursive(int sigs, void (*f)(int)) 50void FAST_FUNC bb_signals_recursive_norestart(int sigs, void (*f)(int))
51{ 51{
52 int sig_no = 0; 52 int sig_no = 0;
53 int bit = 1; 53 int bit = 1;
diff --git a/runit/runsv.c b/runit/runsv.c
index 123720864..f83d58283 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -455,9 +455,9 @@ int runsv_main(int argc UNUSED_PARAM, char **argv)
455 ndelay_on(selfpipe.wr); 455 ndelay_on(selfpipe.wr);
456 456
457 sig_block(SIGCHLD); 457 sig_block(SIGCHLD);
458 bb_signals_recursive(1 << SIGCHLD, s_child); 458 bb_signals_recursive_norestart(1 << SIGCHLD, s_child);
459 sig_block(SIGTERM); 459 sig_block(SIGTERM);
460 bb_signals_recursive(1 << SIGTERM, s_term); 460 bb_signals_recursive_norestart(1 << SIGTERM, s_term);
461 461
462 xchdir(dir); 462 xchdir(dir);
463 /* bss: svd[0].pid = 0; */ 463 /* bss: svd[0].pid = 0; */
diff --git a/runit/svlogd.c b/runit/svlogd.c
index 9beb9f53f..9609fa37c 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -912,10 +912,10 @@ int svlogd_main(int argc, char **argv)
912 sigaddset(&blocked_sigset, SIGALRM); 912 sigaddset(&blocked_sigset, SIGALRM);
913 sigaddset(&blocked_sigset, SIGHUP); 913 sigaddset(&blocked_sigset, SIGHUP);
914 sigprocmask(SIG_BLOCK, &blocked_sigset, NULL); 914 sigprocmask(SIG_BLOCK, &blocked_sigset, NULL);
915 bb_signals_recursive(1 << SIGTERM, sig_term_handler); 915 bb_signals_recursive_norestart(1 << SIGTERM, sig_term_handler);
916 bb_signals_recursive(1 << SIGCHLD, sig_child_handler); 916 bb_signals_recursive_norestart(1 << SIGCHLD, sig_child_handler);
917 bb_signals_recursive(1 << SIGALRM, sig_alarm_handler); 917 bb_signals_recursive_norestart(1 << SIGALRM, sig_alarm_handler);
918 bb_signals_recursive(1 << SIGHUP, sig_hangup_handler); 918 bb_signals_recursive_norestart(1 << SIGHUP, sig_hangup_handler);
919 919
920 logdirs_reopen(); 920 logdirs_reopen();
921 921