less,klogd,syslogd,nc,tcpudp: exit on signal by killing itself, not exit(1)
*: minor shrink
This commit is contained in:
parent
d553faf5a5
commit
400d8bb45e
@ -141,7 +141,7 @@ int dd_main(int argc, char **argv)
|
|||||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||||
sigact.sa_handler = dd_output_status;
|
sigact.sa_handler = dd_output_status;
|
||||||
sigact.sa_flags = SA_RESTART;
|
sigact.sa_flags = SA_RESTART;
|
||||||
sigemptyset(&sigact.sa_mask);
|
/*sigemptyset(&sigact.sa_mask); - memset did it */
|
||||||
sigaction(SIGUSR1, &sigact, NULL);
|
sigaction(SIGUSR1, &sigact, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -164,9 +164,9 @@ int dd_main(int argc, char **argv)
|
|||||||
if (what == 0)
|
if (what == 0)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
arg += key_len;
|
arg += key_len;
|
||||||
/* Must fit into positive ssize_t */
|
|
||||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||||
if (what == OP_ibs) {
|
if (what == OP_ibs) {
|
||||||
|
/* Must fit into positive ssize_t */
|
||||||
ibs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
ibs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ int dd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (what == OP_conv) {
|
if (what == OP_conv) {
|
||||||
while (1) {
|
while (1) {
|
||||||
/* find ',', replace them with nil so we can use arg for
|
/* find ',', replace them with NUL so we can use arg for
|
||||||
* index_in_strings() without copying.
|
* index_in_strings() without copying.
|
||||||
* We rely on arg being non-null, else strchr would fault.
|
* We rely on arg being non-null, else strchr would fault.
|
||||||
*/
|
*/
|
||||||
|
@ -1168,8 +1168,8 @@ int fsck_main(int argc, char **argv)
|
|||||||
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sa_handler = signal_cancel;
|
sa.sa_handler = signal_cancel;
|
||||||
sigaction(SIGINT, &sa, 0);
|
sigaction(SIGINT, &sa, NULL);
|
||||||
sigaction(SIGTERM, &sa, 0);
|
sigaction(SIGTERM, &sa, NULL);
|
||||||
|
|
||||||
setbuf(stdout, NULL);
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
|
@ -309,6 +309,7 @@ void sig_block(int);
|
|||||||
void sig_unblock(int);
|
void sig_unblock(int);
|
||||||
/* UNUSED: void sig_blocknone(void); */
|
/* UNUSED: void sig_blocknone(void); */
|
||||||
void sig_pause(void);
|
void sig_pause(void);
|
||||||
|
void kill_myself_with_sig(int sig) ATTRIBUTE_NORETURN;
|
||||||
|
|
||||||
|
|
||||||
void xsetgid(gid_t gid);
|
void xsetgid(gid_t gid);
|
||||||
|
@ -68,7 +68,7 @@ static void sig_term_handler(int sig)
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("%s: info: sigterm received, exit\n", applet_name);
|
printf("%s: info: sigterm received, exit\n", applet_name);
|
||||||
exit(0);
|
kill_myself_with_sig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Little bloated, but tries to give accurate info how child exited.
|
/* Little bloated, but tries to give accurate info how child exited.
|
||||||
|
@ -78,3 +78,17 @@ void sig_pause(void)
|
|||||||
sigemptyset(&ss);
|
sigemptyset(&ss);
|
||||||
sigsuspend(&ss);
|
sigsuspend(&ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assuming the sig is fatal */
|
||||||
|
void kill_myself_with_sig(int sig)
|
||||||
|
{
|
||||||
|
sigset_t set;
|
||||||
|
|
||||||
|
signal(sig, SIG_DFL);
|
||||||
|
|
||||||
|
sigemptyset(&set);
|
||||||
|
sigaddset(&set, sig);
|
||||||
|
sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||||
|
raise(sig);
|
||||||
|
_exit(1); /* Should not reach it */
|
||||||
|
}
|
||||||
|
@ -214,13 +214,12 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED)
|
|||||||
* arrive here when their connection is broken.
|
* arrive here when their connection is broken.
|
||||||
* We don't want to block here */
|
* We don't want to block here */
|
||||||
ndelay_on(1);
|
ndelay_on(1);
|
||||||
ndelay_on(2);
|
|
||||||
printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT);
|
printf("\r\nLogin timed out after %d seconds\r\n", TIMEOUT);
|
||||||
|
fflush(stdout);
|
||||||
/* unix API is brain damaged regarding O_NONBLOCK,
|
/* unix API is brain damaged regarding O_NONBLOCK,
|
||||||
* we should undo it, or else we can affect other processes */
|
* we should undo it, or else we can affect other processes */
|
||||||
ndelay_off(1);
|
ndelay_off(1);
|
||||||
ndelay_off(2);
|
_exit(EXIT_SUCCESS);
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
|
@ -174,7 +174,9 @@ static void less_exit(int code)
|
|||||||
{
|
{
|
||||||
bb_putchar('\n');
|
bb_putchar('\n');
|
||||||
set_tty_cooked();
|
set_tty_cooked();
|
||||||
exit(code); /* TODO: "suicide mode" for code == -signal */
|
if (code < 0)
|
||||||
|
kill_myself_with_sig(- code); /* does not return */
|
||||||
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the cursor to a position (x,y), where (0,0) is the
|
/* Move the cursor to a position (x,y), where (0,0) is the
|
||||||
@ -1328,9 +1330,9 @@ static void keypress_process(int keypress)
|
|||||||
number_process(keypress);
|
number_process(keypress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sig_catcher(int sig ATTRIBUTE_UNUSED)
|
static void sig_catcher(int sig)
|
||||||
{
|
{
|
||||||
less_exit(1) /* TODO: "suicide mode" for code == -signal */
|
less_exit(- sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
|
@ -43,7 +43,7 @@ Cf:
|
|||||||
#define TIMEOUT_LONG 10
|
#define TIMEOUT_LONG 10
|
||||||
#define MAXERRORS 10
|
#define MAXERRORS 10
|
||||||
|
|
||||||
static int read_byte(int fd, unsigned int timeout)
|
static int read_byte(int fd, unsigned timeout)
|
||||||
{
|
{
|
||||||
char buf[1];
|
char buf[1];
|
||||||
int n;
|
int n;
|
||||||
|
@ -1327,7 +1327,7 @@ int inetd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset((char *) &sa, 0, sizeof(sa));
|
memset((char *) &sa, 0, sizeof(sa));
|
||||||
sigemptyset(&sa.sa_mask);
|
/*sigemptyset(&sa.sa_mask); - memset did it */
|
||||||
sigaddset(&sa.sa_mask, SIGALRM);
|
sigaddset(&sa.sa_mask, SIGALRM);
|
||||||
sigaddset(&sa.sa_mask, SIGCHLD);
|
sigaddset(&sa.sa_mask, SIGCHLD);
|
||||||
sigaddset(&sa.sa_mask, SIGHUP);
|
sigaddset(&sa.sa_mask, SIGHUP);
|
||||||
|
@ -163,7 +163,7 @@ static void catch(int sig)
|
|||||||
if (o_verbose > 1) /* normally we don't care */
|
if (o_verbose > 1) /* normally we don't care */
|
||||||
fprintf(stderr, SENT_N_RECV_M, wrote_net, wrote_out);
|
fprintf(stderr, SENT_N_RECV_M, wrote_net, wrote_out);
|
||||||
fprintf(stderr, "punt!\n");
|
fprintf(stderr, "punt!\n");
|
||||||
exit(1);
|
kill_myself_with_sig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unarm */
|
/* unarm */
|
||||||
|
@ -43,7 +43,7 @@ static void save_state(void)
|
|||||||
xioctl(handle, TIOCGETD, &saved_disc);
|
xioctl(handle, TIOCGETD, &saved_disc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_termios_state_and_warn(struct termios *state)
|
static int set_termios_state_or_warn(struct termios *state)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -78,12 +78,12 @@ static void restore_state_and_exit(int exitcode)
|
|||||||
memcpy(&state, &saved_state, sizeof(state));
|
memcpy(&state, &saved_state, sizeof(state));
|
||||||
cfsetispeed(&state, B0);
|
cfsetispeed(&state, B0);
|
||||||
cfsetospeed(&state, B0);
|
cfsetospeed(&state, B0);
|
||||||
if (set_termios_state_and_warn(&state))
|
if (set_termios_state_or_warn(&state))
|
||||||
exitcode = 1;
|
exitcode = 1;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
/* Restore line status */
|
/* Restore line status */
|
||||||
if (set_termios_state_and_warn(&saved_state))
|
if (set_termios_state_or_warn(&saved_state))
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
if (ENABLE_FEATURE_CLEAN_UP)
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
close(handle);
|
close(handle);
|
||||||
@ -99,7 +99,7 @@ static void set_state(struct termios *state, int encap)
|
|||||||
int disc;
|
int disc;
|
||||||
|
|
||||||
/* Set line status */
|
/* Set line status */
|
||||||
if (set_termios_state_and_warn(state))
|
if (set_termios_state_or_warn(state))
|
||||||
goto bad;
|
goto bad;
|
||||||
/* Set line discliple (N_SLIP always) */
|
/* Set line discliple (N_SLIP always) */
|
||||||
disc = N_SLIP;
|
disc = N_SLIP;
|
||||||
|
@ -808,12 +808,7 @@ static void sigexit(int sig)
|
|||||||
if (sig <= 0)
|
if (sig <= 0)
|
||||||
_exit(- sig);
|
_exit(- sig);
|
||||||
|
|
||||||
/* Enable only this sig and kill ourself with it */
|
kill_myself_with_sig(sig); /* does not return */
|
||||||
signal(sig, SIG_DFL);
|
|
||||||
sigdelset(&block_all, sig);
|
|
||||||
sigprocmask(SIG_SETMASK, &block_all, NULL);
|
|
||||||
raise(sig);
|
|
||||||
_exit(1); /* Should not reach it */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restores tty foreground process group, and exits. */
|
/* Restores tty foreground process group, and exits. */
|
||||||
|
@ -26,7 +26,7 @@ static void klogd_signal(int sig ATTRIBUTE_UNUSED)
|
|||||||
klogctl(7, NULL, 0);
|
klogctl(7, NULL, 0);
|
||||||
klogctl(0, NULL, 0);
|
klogctl(0, NULL, 0);
|
||||||
syslog(LOG_NOTICE, "klogd: exiting");
|
syslog(LOG_NOTICE, "klogd: exiting");
|
||||||
exit(EXIT_SUCCESS);
|
kill_myself_with_sig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define log_buffer bb_common_bufsiz1
|
#define log_buffer bb_common_bufsiz1
|
||||||
|
@ -475,7 +475,7 @@ static void quit_signal(int sig)
|
|||||||
puts("syslogd exiting");
|
puts("syslogd exiting");
|
||||||
if (ENABLE_FEATURE_IPC_SYSLOG)
|
if (ENABLE_FEATURE_IPC_SYSLOG)
|
||||||
ipcsyslog_cleanup();
|
ipcsyslog_cleanup();
|
||||||
exit(1);
|
kill_myself_with_sig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYSLOGD_MARK
|
#ifdef SYSLOGD_MARK
|
||||||
|
Loading…
Reference in New Issue
Block a user