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
This commit is contained in:
Denis Vlasenko
2008-02-16 22:58:56 +00:00
parent 7fc294cdfe
commit 25591c322c
26 changed files with 249 additions and 154 deletions

View File

@@ -361,14 +361,16 @@ int dnsd_main(int argc, char **argv)
dnsentryinit();
signal(SIGINT, interrupt);
/* why? signal(SIGPIPE, SIG_IGN); */
signal(SIGHUP, SIG_IGN);
bb_signals(0
/* why? + (1 << SIGPIPE) */
+ (1 << SIGHUP)
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
+ (1 << SIGTSTP)
#endif
#ifdef SIGURG
signal(SIGURG, SIG_IGN);
+ (1 << SIGURG)
#endif
, SIG_IGN);
lsa = xdotted2sockaddr(listen_interface, port);
udps = xsocket(lsa->u.sa.sa_family, SOCK_DGRAM, 0);

View File

@@ -683,14 +683,18 @@ int nc_main(int argc, char **argv)
PTR_TO_GLOBALS = xzalloc(sizeof(G));
/* catch a signal or two for cleanup */
signal(SIGINT, catch);
signal(SIGQUIT, catch);
signal(SIGTERM, catch);
bb_signals(0
+ (1 << SIGINT)
+ (1 << SIGQUIT)
+ (1 << SIGTERM)
, catch);
/* and suppress others... */
bb_signals(0
#ifdef SIGURG
signal(SIGURG, SIG_IGN);
+ (1 << SIGURG)
#endif
signal(SIGPIPE, SIG_IGN); /* important! */
+ (1 << SIGPIPE) /* important! */
, SIG_IGN);
proggie = argv;
while (*++proggie) {

View File

@@ -111,8 +111,10 @@ static void launch_helper(const char **argv)
_exit(127);
}
// parent - check whether child is alive
sig_catch(SIGCHLD, signal_handler);
sig_catch(SIGALRM, signal_handler);
bb_signals_recursive(0
+ (1 << SIGCHLD)
+ (1 << SIGALRM)
, signal_handler);
signal_handler(SIGCHLD);
// child seems OK -> parent goes on
}

View File

@@ -175,10 +175,12 @@ int slattach_main(int argc, char **argv)
/* Trap signals in order to restore tty states upon exit */
if (!(opt & OPT_e_quit)) {
signal(SIGHUP, sig_handler);
signal(SIGINT, sig_handler);
signal(SIGQUIT, sig_handler);
signal(SIGTERM, sig_handler);
bb_signals(0
+ (1 << SIGHUP)
+ (1 << SIGINT)
+ (1 << SIGQUIT)
+ (1 << SIGTERM)
, sig_handler);
}
/* Open tty */

View File

@@ -279,8 +279,7 @@ make_new_session(
setsid();
/* Restore default signal handling */
signal(SIGCHLD, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
/* open the child's side of the tty. */
/* NB: setsid() disconnects from any previous ctty's. Therefore

View File

@@ -42,9 +42,11 @@ void udhcp_sp_setup(void)
close_on_exec_on(signal_pipe.rd);
close_on_exec_on(signal_pipe.wr);
ndelay_on(signal_pipe.wr);
signal(SIGUSR1, signal_handler);
signal(SIGUSR2, signal_handler);
signal(SIGTERM, signal_handler);
bb_signals(0
+ (1 << SIGUSR1)
+ (1 << SIGUSR2)
+ (1 << SIGTERM)
, signal_handler);
}