From 25591c322c9305bd54d3ab80cfaf01ef87640d77 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 16 Feb 2008 22:58:56 +0000 Subject: libbb: introduce bb_signals and bb_signals_recursive, which sets same handler for many signals. sig_catch is nuked (bb_signals_recursive is more descriptive name). *: use them as appropriate. function old new delta bb_signals_recursive - 95 +95 bb_signals - 52 +52 run_command 258 273 +15 svlogd_main 1368 1377 +9 runsv_main 1746 1752 +6 runsvdir_main 1643 1646 +3 UNSPEC_print 64 66 +2 time_main 1128 1127 -1 ... resize_main 246 210 -36 sig_catch 63 - -63 set_fatal_sighandler 85 14 -71 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 5/24 up/down: 182/-548) Total: -366 bytes --- init/init.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'init/init.c') diff --git a/init/init.c b/init/init.c index 9e24817b7..080c5b3af 100644 --- a/init/init.c +++ b/init/init.c @@ -319,15 +319,17 @@ static pid_t run(const struct init_action *a) /* Child */ /* Reset signal handlers that were set by the parent process */ - signal(SIGUSR1, SIG_DFL); - signal(SIGUSR2, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGHUP, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGCONT, SIG_DFL); - signal(SIGSTOP, SIG_DFL); - signal(SIGTSTP, SIG_DFL); + bb_signals(0 + + (1 << SIGUSR1) + + (1 << SIGUSR2) + + (1 << SIGINT) + + (1 << SIGTERM) + + (1 << SIGHUP) + + (1 << SIGQUIT) + + (1 << SIGCONT) + + (1 << SIGSTOP) + + (1 << SIGTSTP) + , SIG_DFL); /* Create a new session and make ourself the process * group leader */ @@ -349,9 +351,11 @@ static pid_t run(const struct init_action *a) if (pid > 0) { /* Parent - wait till the child is done */ - signal(SIGINT, SIG_IGN); - signal(SIGTSTP, SIG_IGN); - signal(SIGQUIT, SIG_IGN); + bb_signals(0 + + (1 << SIGINT) + + (1 << SIGTSTP) + + (1 << SIGQUIT) + , SIG_IGN); signal(SIGCHLD, SIG_DFL); waitfor(pid); @@ -864,15 +868,21 @@ int init_main(int argc, char **argv) } /* Set up sig handlers -- be sure to * clear all of these in run() */ - signal(SIGHUP, exec_restart_action); - signal(SIGQUIT, exec_restart_action); - signal(SIGUSR1, halt_reboot_pwoff); /* halt */ - signal(SIGUSR2, halt_reboot_pwoff); /* poweroff */ - signal(SIGTERM, halt_reboot_pwoff); /* reboot */ + bb_signals(0 + + (1 << SIGHUP) + + (1 << SIGQUIT) + , exec_restart_action); + bb_signals(0 + + (1 << SIGUSR1) /* halt */ + + (1 << SIGUSR2) /* poweroff */ + + (1 << SIGTERM) /* reboot */ + , halt_reboot_pwoff); signal(SIGINT, ctrlaltdel_signal); signal(SIGCONT, cont_handler); - signal(SIGSTOP, stop_handler); - signal(SIGTSTP, stop_handler); + bb_signals(0 + + (1 << SIGSTOP) + + (1 << SIGTSTP) + , stop_handler); /* Turn off rebooting via CTL-ALT-DEL -- we get a * SIGINT on CAD so we can shut things down gracefully... */ -- cgit v1.2.3