diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-24 13:36:01 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-24 13:36:01 +0000 |
commit | 400d8bb45ee25ce226bb343a3dfaab84e6d3a8e1 (patch) | |
tree | aa3cdc9a663f1ac2467803fc215899d86ed1db74 | |
parent | d553faf5a53cf9d72e16fc789451a92a797f1b70 (diff) | |
download | busybox-w32-400d8bb45ee25ce226bb343a3dfaab84e6d3a8e1.tar.gz busybox-w32-400d8bb45ee25ce226bb343a3dfaab84e6d3a8e1.tar.bz2 busybox-w32-400d8bb45ee25ce226bb343a3dfaab84e6d3a8e1.zip |
less,klogd,syslogd,nc,tcpudp: exit on signal by killing itself, not exit(1)
*: minor shrink
-rw-r--r-- | coreutils/dd.c | 66 | ||||
-rw-r--r-- | e2fsprogs/fsck.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | ipsvd/tcpudp.c | 2 | ||||
-rw-r--r-- | libbb/signals.c | 14 | ||||
-rw-r--r-- | loginutils/login.c | 5 | ||||
-rw-r--r-- | miscutils/less.c | 8 | ||||
-rw-r--r-- | miscutils/rx.c | 2 | ||||
-rw-r--r-- | networking/inetd.c | 2 | ||||
-rw-r--r-- | networking/nc_bloaty.c | 2 | ||||
-rw-r--r-- | networking/slattach.c | 8 | ||||
-rw-r--r-- | shell/hush.c | 7 | ||||
-rw-r--r-- | sysklogd/klogd.c | 2 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 2 |
14 files changed, 68 insertions, 57 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 7552c8518..961b1fff7 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -141,7 +141,7 @@ int dd_main(int argc, char **argv) | |||
141 | #if ENABLE_FEATURE_DD_SIGNAL_HANDLING | 141 | #if ENABLE_FEATURE_DD_SIGNAL_HANDLING |
142 | sigact.sa_handler = dd_output_status; | 142 | sigact.sa_handler = dd_output_status; |
143 | sigact.sa_flags = SA_RESTART; | 143 | sigact.sa_flags = SA_RESTART; |
144 | sigemptyset(&sigact.sa_mask); | 144 | /*sigemptyset(&sigact.sa_mask); - memset did it */ |
145 | sigaction(SIGUSR1, &sigact, NULL); | 145 | sigaction(SIGUSR1, &sigact, NULL); |
146 | #endif | 146 | #endif |
147 | 147 | ||
@@ -164,40 +164,40 @@ int dd_main(int argc, char **argv) | |||
164 | if (what == 0) | 164 | if (what == 0) |
165 | bb_show_usage(); | 165 | bb_show_usage(); |
166 | arg += key_len; | 166 | arg += key_len; |
167 | /* Must fit into positive ssize_t */ | ||
168 | #if ENABLE_FEATURE_DD_IBS_OBS | 167 | #if ENABLE_FEATURE_DD_IBS_OBS |
169 | if (what == OP_ibs) { | 168 | if (what == OP_ibs) { |
170 | ibs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes); | 169 | /* Must fit into positive ssize_t */ |
171 | continue; | 170 | ibs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes); |
172 | } | 171 | continue; |
173 | if (what == OP_obs) { | 172 | } |
174 | obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes); | 173 | if (what == OP_obs) { |
175 | continue; | 174 | obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes); |
176 | } | 175 | continue; |
177 | if (what == OP_conv) { | 176 | } |
178 | while (1) { | 177 | if (what == OP_conv) { |
179 | /* find ',', replace them with nil so we can use arg for | 178 | while (1) { |
180 | * index_in_strings() without copying. | 179 | /* find ',', replace them with NUL so we can use arg for |
181 | * We rely on arg being non-null, else strchr would fault. | 180 | * index_in_strings() without copying. |
182 | */ | 181 | * We rely on arg being non-null, else strchr would fault. |
183 | key = strchr(arg, ','); | 182 | */ |
184 | if (key) | 183 | key = strchr(arg, ','); |
185 | *key = '\0'; | 184 | if (key) |
186 | what = index_in_strings(keywords, arg) + 1; | 185 | *key = '\0'; |
187 | if (what < OP_conv_notrunc) | 186 | what = index_in_strings(keywords, arg) + 1; |
188 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); | 187 | if (what < OP_conv_notrunc) |
189 | if (what == OP_conv_notrunc) | 188 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); |
190 | flags |= FLAG_NOTRUNC; | 189 | if (what == OP_conv_notrunc) |
191 | if (what == OP_conv_sync) | 190 | flags |= FLAG_NOTRUNC; |
192 | flags |= FLAG_SYNC; | 191 | if (what == OP_conv_sync) |
193 | if (what == OP_conv_noerror) | 192 | flags |= FLAG_SYNC; |
194 | flags |= FLAG_NOERROR; | 193 | if (what == OP_conv_noerror) |
195 | if (!key) /* no ',' left, so this was the last specifier */ | 194 | flags |= FLAG_NOERROR; |
196 | break; | 195 | if (!key) /* no ',' left, so this was the last specifier */ |
197 | arg = key + 1; /* skip this keyword and ',' */ | 196 | break; |
198 | } | 197 | arg = key + 1; /* skip this keyword and ',' */ |
199 | continue; | ||
200 | } | 198 | } |
199 | continue; | ||
200 | } | ||
201 | #endif | 201 | #endif |
202 | if (what == OP_bs) { | 202 | if (what == OP_bs) { |
203 | ibs = obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes); | 203 | ibs = obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes); |
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 012285103..de2d61eef 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -1168,8 +1168,8 @@ int fsck_main(int argc, char **argv) | |||
1168 | 1168 | ||
1169 | memset(&sa, 0, sizeof(sa)); | 1169 | memset(&sa, 0, sizeof(sa)); |
1170 | sa.sa_handler = signal_cancel; | 1170 | sa.sa_handler = signal_cancel; |
1171 | sigaction(SIGINT, &sa, 0); | 1171 | sigaction(SIGINT, &sa, NULL); |
1172 | sigaction(SIGTERM, &sa, 0); | 1172 | sigaction(SIGTERM, &sa, NULL); |
1173 | 1173 | ||
1174 | setbuf(stdout, NULL); | 1174 | setbuf(stdout, NULL); |
1175 | 1175 | ||
diff --git a/include/libbb.h b/include/libbb.h index 873ab8798..48937c4b1 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -309,6 +309,7 @@ void sig_block(int); | |||
309 | void sig_unblock(int); | 309 | void sig_unblock(int); |
310 | /* UNUSED: void sig_blocknone(void); */ | 310 | /* UNUSED: void sig_blocknone(void); */ |
311 | void sig_pause(void); | 311 | void sig_pause(void); |
312 | void kill_myself_with_sig(int sig) ATTRIBUTE_NORETURN; | ||
312 | 313 | ||
313 | 314 | ||
314 | void xsetgid(gid_t gid); | 315 | void xsetgid(gid_t gid); |
diff --git a/ipsvd/tcpudp.c b/ipsvd/tcpudp.c index dc61d6f76..b3a2c7a77 100644 --- a/ipsvd/tcpudp.c +++ b/ipsvd/tcpudp.c | |||
@@ -68,7 +68,7 @@ static void sig_term_handler(int sig) | |||
68 | { | 68 | { |
69 | if (verbose) | 69 | if (verbose) |
70 | printf("%s: info: sigterm received, exit\n", applet_name); | 70 | printf("%s: info: sigterm received, exit\n", applet_name); |
71 | exit(0); | 71 | kill_myself_with_sig(sig); |
72 | } | 72 | } |
73 | 73 | ||
74 | /* Little bloated, but tries to give accurate info how child exited. | 74 | /* Little bloated, but tries to give accurate info how child exited. |
diff --git a/libbb/signals.c b/libbb/signals.c index f7e4908e7..b46b595da 100644 --- a/libbb/signals.c +++ b/libbb/signals.c | |||
@@ -78,3 +78,17 @@ void sig_pause(void) | |||
78 | sigemptyset(&ss); | 78 | sigemptyset(&ss); |
79 | sigsuspend(&ss); | 79 | sigsuspend(&ss); |
80 | } | 80 | } |
81 | |||
82 | /* Assuming the sig is fatal */ | ||
83 | void kill_myself_with_sig(int sig) | ||
84 | { | ||
85 | sigset_t set; | ||
86 | |||
87 | signal(sig, SIG_DFL); | ||
88 | |||
89 | sigemptyset(&set); | ||
90 | sigaddset(&set, sig); | ||
91 | sigprocmask(SIG_UNBLOCK, &set, NULL); | ||
92 | raise(sig); | ||
93 | _exit(1); /* Should not reach it */ | ||
94 | } | ||
diff --git a/loginutils/login.c b/loginutils/login.c index a5b6369ff..bc437bb6b 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -214,13 +214,12 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED) | |||
214 | * arrive here when their connection is broken. | 214 | * arrive here when their connection is broken. |
215 | * We don't want to block here */ | 215 | * We don't want to block here */ |
216 | ndelay_on(1); | 216 | ndelay_on(1); |
217 | ndelay_on(2); | ||
218 | printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT); | 217 | printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT); |
218 | fflush(stdout); | ||
219 | /* unix API is brain damaged regarding O_NONBLOCK, | 219 | /* unix API is brain damaged regarding O_NONBLOCK, |
220 | * we should undo it, or else we can affect other processes */ | 220 | * we should undo it, or else we can affect other processes */ |
221 | ndelay_off(1); | 221 | ndelay_off(1); |
222 | ndelay_off(2); | 222 | _exit(EXIT_SUCCESS); |
223 | exit(EXIT_SUCCESS); | ||
224 | } | 223 | } |
225 | 224 | ||
226 | int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 225 | int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/miscutils/less.c b/miscutils/less.c index f3be2cfbf..7351a634d 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -174,7 +174,9 @@ static void less_exit(int code) | |||
174 | { | 174 | { |
175 | bb_putchar('\n'); | 175 | bb_putchar('\n'); |
176 | set_tty_cooked(); | 176 | set_tty_cooked(); |
177 | exit(code); /* TODO: "suicide mode" for code == -signal */ | 177 | if (code < 0) |
178 | kill_myself_with_sig(- code); /* does not return */ | ||
179 | exit(code); | ||
178 | } | 180 | } |
179 | 181 | ||
180 | /* Move the cursor to a position (x,y), where (0,0) is the | 182 | /* Move the cursor to a position (x,y), where (0,0) is the |
@@ -1328,9 +1330,9 @@ static void keypress_process(int keypress) | |||
1328 | number_process(keypress); | 1330 | number_process(keypress); |
1329 | } | 1331 | } |
1330 | 1332 | ||
1331 | static void sig_catcher(int sig ATTRIBUTE_UNUSED) | 1333 | static void sig_catcher(int sig) |
1332 | { | 1334 | { |
1333 | less_exit(1) /* TODO: "suicide mode" for code == -signal */ | 1335 | less_exit(- sig); |
1334 | } | 1336 | } |
1335 | 1337 | ||
1336 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1338 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/miscutils/rx.c b/miscutils/rx.c index 898703c59..8ccea4974 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c | |||
@@ -43,7 +43,7 @@ Cf: | |||
43 | #define TIMEOUT_LONG 10 | 43 | #define TIMEOUT_LONG 10 |
44 | #define MAXERRORS 10 | 44 | #define MAXERRORS 10 |
45 | 45 | ||
46 | static int read_byte(int fd, unsigned int timeout) | 46 | static int read_byte(int fd, unsigned timeout) |
47 | { | 47 | { |
48 | char buf[1]; | 48 | char buf[1]; |
49 | int n; | 49 | int n; |
diff --git a/networking/inetd.c b/networking/inetd.c index a7259f3d4..fd865efd1 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1327,7 +1327,7 @@ int inetd_main(int argc, char **argv) | |||
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | memset((char *) &sa, 0, sizeof(sa)); | 1329 | memset((char *) &sa, 0, sizeof(sa)); |
1330 | sigemptyset(&sa.sa_mask); | 1330 | /*sigemptyset(&sa.sa_mask); - memset did it */ |
1331 | sigaddset(&sa.sa_mask, SIGALRM); | 1331 | sigaddset(&sa.sa_mask, SIGALRM); |
1332 | sigaddset(&sa.sa_mask, SIGCHLD); | 1332 | sigaddset(&sa.sa_mask, SIGCHLD); |
1333 | sigaddset(&sa.sa_mask, SIGHUP); | 1333 | sigaddset(&sa.sa_mask, SIGHUP); |
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 853577aef..dd62e5df7 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -163,7 +163,7 @@ static void catch(int sig) | |||
163 | if (o_verbose > 1) /* normally we don't care */ | 163 | if (o_verbose > 1) /* normally we don't care */ |
164 | fprintf(stderr, SENT_N_RECV_M, wrote_net, wrote_out); | 164 | fprintf(stderr, SENT_N_RECV_M, wrote_net, wrote_out); |
165 | fprintf(stderr, "punt!\n"); | 165 | fprintf(stderr, "punt!\n"); |
166 | exit(1); | 166 | kill_myself_with_sig(sig); |
167 | } | 167 | } |
168 | 168 | ||
169 | /* unarm */ | 169 | /* unarm */ |
diff --git a/networking/slattach.c b/networking/slattach.c index e501d82e1..1987eb39c 100644 --- a/networking/slattach.c +++ b/networking/slattach.c | |||
@@ -43,7 +43,7 @@ static void save_state(void) | |||
43 | xioctl(handle, TIOCGETD, &saved_disc); | 43 | xioctl(handle, TIOCGETD, &saved_disc); |
44 | } | 44 | } |
45 | 45 | ||
46 | static int set_termios_state_and_warn(struct termios *state) | 46 | static int set_termios_state_or_warn(struct termios *state) |
47 | { | 47 | { |
48 | int ret; | 48 | int ret; |
49 | 49 | ||
@@ -78,12 +78,12 @@ static void restore_state_and_exit(int exitcode) | |||
78 | memcpy(&state, &saved_state, sizeof(state)); | 78 | memcpy(&state, &saved_state, sizeof(state)); |
79 | cfsetispeed(&state, B0); | 79 | cfsetispeed(&state, B0); |
80 | cfsetospeed(&state, B0); | 80 | cfsetospeed(&state, B0); |
81 | if (set_termios_state_and_warn(&state)) | 81 | if (set_termios_state_or_warn(&state)) |
82 | exitcode = 1; | 82 | exitcode = 1; |
83 | sleep(1); | 83 | sleep(1); |
84 | 84 | ||
85 | /* Restore line status */ | 85 | /* Restore line status */ |
86 | if (set_termios_state_and_warn(&saved_state)) | 86 | if (set_termios_state_or_warn(&saved_state)) |
87 | exit(EXIT_FAILURE); | 87 | exit(EXIT_FAILURE); |
88 | if (ENABLE_FEATURE_CLEAN_UP) | 88 | if (ENABLE_FEATURE_CLEAN_UP) |
89 | close(handle); | 89 | close(handle); |
@@ -99,7 +99,7 @@ static void set_state(struct termios *state, int encap) | |||
99 | int disc; | 99 | int disc; |
100 | 100 | ||
101 | /* Set line status */ | 101 | /* Set line status */ |
102 | if (set_termios_state_and_warn(state)) | 102 | if (set_termios_state_or_warn(state)) |
103 | goto bad; | 103 | goto bad; |
104 | /* Set line discliple (N_SLIP always) */ | 104 | /* Set line discliple (N_SLIP always) */ |
105 | disc = N_SLIP; | 105 | disc = N_SLIP; |
diff --git a/shell/hush.c b/shell/hush.c index 820fd888d..d9ef2390e 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -808,12 +808,7 @@ static void sigexit(int sig) | |||
808 | if (sig <= 0) | 808 | if (sig <= 0) |
809 | _exit(- sig); | 809 | _exit(- sig); |
810 | 810 | ||
811 | /* Enable only this sig and kill ourself with it */ | 811 | kill_myself_with_sig(sig); /* does not return */ |
812 | signal(sig, SIG_DFL); | ||
813 | sigdelset(&block_all, sig); | ||
814 | sigprocmask(SIG_SETMASK, &block_all, NULL); | ||
815 | raise(sig); | ||
816 | _exit(1); /* Should not reach it */ | ||
817 | } | 812 | } |
818 | 813 | ||
819 | /* Restores tty foreground process group, and exits. */ | 814 | /* Restores tty foreground process group, and exits. */ |
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 6a675b8b3..01d597178 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -26,7 +26,7 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED) | |||
26 | klogctl(7, NULL, 0); | 26 | klogctl(7, NULL, 0); |
27 | klogctl(0, NULL, 0); | 27 | klogctl(0, NULL, 0); |
28 | syslog(LOG_NOTICE, "klogd: exiting"); | 28 | syslog(LOG_NOTICE, "klogd: exiting"); |
29 | exit(EXIT_SUCCESS); | 29 | kill_myself_with_sig(sig); |
30 | } | 30 | } |
31 | 31 | ||
32 | #define log_buffer bb_common_bufsiz1 | 32 | #define log_buffer bb_common_bufsiz1 |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index c71350750..0dc69d8cc 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -475,7 +475,7 @@ static void quit_signal(int sig) | |||
475 | puts("syslogd exiting"); | 475 | puts("syslogd exiting"); |
476 | if (ENABLE_FEATURE_IPC_SYSLOG) | 476 | if (ENABLE_FEATURE_IPC_SYSLOG) |
477 | ipcsyslog_cleanup(); | 477 | ipcsyslog_cleanup(); |
478 | exit(1); | 478 | kill_myself_with_sig(sig); |
479 | } | 479 | } |
480 | 480 | ||
481 | #ifdef SYSLOGD_MARK | 481 | #ifdef SYSLOGD_MARK |