summaryrefslogtreecommitdiff
path: root/runit/runsvdir.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-09-11 19:51:11 +0000
committerDenis Vlasenko2008-09-11 19:51:11 +0000
commit08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32 (patch)
tree84049bf86fbcbe95ad0443816efd07f8c02c1288 /runit/runsvdir.c
parent9725daa03a7806b1c9c5a3c511dfe2ff9f97dd26 (diff)
downloadbusybox-08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32.zip
busybox-08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32.tar.gz
runsvd: shrink by Vladimir
*: use unified trivial signal handler function old new delta record_signo - 10 +10 process_stdin 433 443 +10 bbunpack 383 391 +8 wc_main 598 605 +7 conescape 293 296 +3 nmeter_main 670 672 +2 fallbackSort 1717 1719 +2 bb_got_signal - 1 +1 microcom_main 713 712 -1 signalled 2 - -2 pack_gzip 1661 1659 -2 evalvar 1376 1374 -2 compare_keys 737 735 -2 parse_command 1460 1456 -4 expand 1748 1744 -4 s_term 37 29 -8 s_hangup 8 - -8 fgotsig 10 - -10 find_pair 187 169 -18 signal_handler 190 170 -20 runsvdir_main 1701 1583 -118 ------------------------------------------------------------------------------ (add/remove: 2/3 grow/shrink: 6/10 up/down: 43/-199) Total: -156 bytes
Diffstat (limited to 'runit/runsvdir.c')
-rw-r--r--runit/runsvdir.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/runit/runsvdir.c b/runit/runsvdir.c
index aaa4c47..0dedd5c 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -52,7 +52,6 @@ struct globals {
struct pollfd pfd[1];
unsigned stamplog;
smallint check; /* = 1; */
- smallint exitsoon;
smallint set_pgrp;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
@@ -65,7 +64,6 @@ struct globals {
#define pfd (G.pfd )
#define stamplog (G.stamplog )
#define check (G.check )
-#define exitsoon (G.exitsoon )
#define set_pgrp (G.set_pgrp )
#define INIT_G() do { \
check = 1; \
@@ -89,15 +87,6 @@ static void warnx(const char *m1)
warn3x(m1, "", "");
}
-static void s_term(int sig_no UNUSED_PARAM)
-{
- exitsoon = 1;
-}
-static void s_hangup(int sig_no UNUSED_PARAM)
-{
- exitsoon = 2;
-}
-
static void runsv(int no, const char *name)
{
pid_t pid;
@@ -246,20 +235,11 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
- argv++;
- if (!*argv)
- bb_show_usage();
- if (argv[0][0] == '-') {
- switch (argv[0][1]) {
- case 'P': set_pgrp = 1;
- case '-': ++argv;
- }
- if (!*argv)
- bb_show_usage();
- }
+ opt_complementary = "-1";
+ set_pgrp = getopt32(argv, "P");
+ argv += optind;
- bb_signals_recursive(1 << SIGTERM, s_term);
- bb_signals_recursive(1 << SIGHUP, s_hangup);
+ bb_signals_recursive((1 << SIGTERM) | (1 << SIGHUP), record_signo);
svdir = *argv++;
if (argv && *argv) {
rplog = *argv;
@@ -346,14 +326,14 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
}
}
- switch (exitsoon) {
- case 1:
- _exit(EXIT_SUCCESS);
- case 2:
+ switch (bb_got_signal) {
+ case SIGHUP:
for (i = 0; i < svnum; i++)
if (sv[i].pid)
kill(sv[i].pid, SIGTERM);
- _exit(111);
+ // N.B. fall through
+ case SIGTERM:
+ _exit((SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS);
}
}
/* not reached */