aboutsummaryrefslogtreecommitdiff
path: root/runit/runsvdir.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-09-11 19:51:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-09-11 19:51:11 +0000
commit08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32 (patch)
tree84049bf86fbcbe95ad0443816efd07f8c02c1288 /runit/runsvdir.c
parent9725daa03a7806b1c9c5a3c511dfe2ff9f97dd26 (diff)
downloadbusybox-w32-08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32.tar.gz
busybox-w32-08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32.tar.bz2
busybox-w32-08ea11ab0749a7977e6d47cd0fa7b3c9cc10af32.zip
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 aaa4c470c..0dedd5c77 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -52,7 +52,6 @@ struct globals {
52 struct pollfd pfd[1]; 52 struct pollfd pfd[1];
53 unsigned stamplog; 53 unsigned stamplog;
54 smallint check; /* = 1; */ 54 smallint check; /* = 1; */
55 smallint exitsoon;
56 smallint set_pgrp; 55 smallint set_pgrp;
57}; 56};
58#define G (*(struct globals*)&bb_common_bufsiz1) 57#define G (*(struct globals*)&bb_common_bufsiz1)
@@ -65,7 +64,6 @@ struct globals {
65#define pfd (G.pfd ) 64#define pfd (G.pfd )
66#define stamplog (G.stamplog ) 65#define stamplog (G.stamplog )
67#define check (G.check ) 66#define check (G.check )
68#define exitsoon (G.exitsoon )
69#define set_pgrp (G.set_pgrp ) 67#define set_pgrp (G.set_pgrp )
70#define INIT_G() do { \ 68#define INIT_G() do { \
71 check = 1; \ 69 check = 1; \
@@ -89,15 +87,6 @@ static void warnx(const char *m1)
89 warn3x(m1, "", ""); 87 warn3x(m1, "", "");
90} 88}
91 89
92static void s_term(int sig_no UNUSED_PARAM)
93{
94 exitsoon = 1;
95}
96static void s_hangup(int sig_no UNUSED_PARAM)
97{
98 exitsoon = 2;
99}
100
101static void runsv(int no, const char *name) 90static void runsv(int no, const char *name)
102{ 91{
103 pid_t pid; 92 pid_t pid;
@@ -246,20 +235,11 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
246 235
247 INIT_G(); 236 INIT_G();
248 237
249 argv++; 238 opt_complementary = "-1";
250 if (!*argv) 239 set_pgrp = getopt32(argv, "P");
251 bb_show_usage(); 240 argv += optind;
252 if (argv[0][0] == '-') {
253 switch (argv[0][1]) {
254 case 'P': set_pgrp = 1;
255 case '-': ++argv;
256 }
257 if (!*argv)
258 bb_show_usage();
259 }
260 241
261 bb_signals_recursive(1 << SIGTERM, s_term); 242 bb_signals_recursive((1 << SIGTERM) | (1 << SIGHUP), record_signo);
262 bb_signals_recursive(1 << SIGHUP, s_hangup);
263 svdir = *argv++; 243 svdir = *argv++;
264 if (argv && *argv) { 244 if (argv && *argv) {
265 rplog = *argv; 245 rplog = *argv;
@@ -346,14 +326,14 @@ int runsvdir_main(int argc UNUSED_PARAM, char **argv)
346 } 326 }
347 } 327 }
348 328
349 switch (exitsoon) { 329 switch (bb_got_signal) {
350 case 1: 330 case SIGHUP:
351 _exit(EXIT_SUCCESS);
352 case 2:
353 for (i = 0; i < svnum; i++) 331 for (i = 0; i < svnum; i++)
354 if (sv[i].pid) 332 if (sv[i].pid)
355 kill(sv[i].pid, SIGTERM); 333 kill(sv[i].pid, SIGTERM);
356 _exit(111); 334 // N.B. fall through
335 case SIGTERM:
336 _exit((SIGHUP == bb_got_signal) ? 111 : EXIT_SUCCESS);
357 } 337 }
358 } 338 }
359 /* not reached */ 339 /* not reached */