int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC;
/* SIG_BLOCK/SIG_UNBLOCK all signals: */
int sigprocmask_allsigs(int how) FAST_FUNC;
+/* Standard handler which just records signo */
+extern smallint bb_got_signal;
+void record_signo(int signo); /* not FAST_FUNC! */
void xsetgid(gid_t gid) FAST_FUNC;
#include "libbb.h"
+/* All known arches use small ints for signals */
+smallint bb_got_signal;
+
+void record_signo(int signo)
+{
+ bb_got_signal = signo;
+}
+
/* Saves 2 bytes on x86! Oh my... */
int FAST_FUNC sigaction_set(int signum, const struct sigaction *act)
{
#include "libbb.h"
#include <linux/inotify.h>
-static volatile smallint signalled;
-
-static void signal_handler(int signo)
-{
- signalled = signo;
-}
-
static const char mask_names[] ALIGN1 =
"a" // 0x00000001 File was accessed
"c" // 0x00000002 File was modified
+ (1 << SIGINT)
+ (1 << SIGTERM)
+ (1 << SIGPIPE)
- , signal_handler);
+ , record_signo);
// do watch
// pfd.fd = fd;
pfd.events = POLLIN;
- while (!signalled && poll(&pfd, 1, -1) > 0) {
+ while (!bb_got_signal && poll(&pfd, 1, -1) > 0) {
ssize_t len;
void *buf;
struct inotify_event *ie;
*/
#include "libbb.h"
-/* All known arches use small ints for signals */
-static volatile smallint signalled;
-
-static void signal_handler(int signo)
-{
- signalled = signo;
-}
-
// set raw tty mode
static void xget1(int fd, struct termios *t, struct termios *oldt)
{
+ (1 << SIGINT)
+ (1 << SIGTERM)
+ (1 << SIGPIPE)
- , signal_handler);
+ , record_signo);
// error exit code if we fail to open the device
- signalled = 1;
+ bb_got_signal = 1;
// open device
sfd = open_or_warn(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK);
pfd[1].fd = STDIN_FILENO;
pfd[1].events = POLLIN;
- signalled = 0;
+ bb_got_signal = 0;
nfd = 2;
- while (!signalled && safe_poll(pfd, nfd, timeout) > 0) {
+ while (!bb_got_signal && safe_poll(pfd, nfd, timeout) > 0) {
if (nfd > 1 && pfd[1].revents) {
char c;
// read from stdin -> write to device
full_write(STDOUT_FILENO, iobuf, len);
else {
// EOF/error -> bail out
- signalled = SIGHUP;
+ bb_got_signal = SIGHUP;
break;
}
}
if (device_lock_file)
unlink(device_lock_file);
- return signalled;
+ return bb_got_signal;
}
byte telwish; /* DO, DONT, WILL, WONT */
byte charmode;
byte telflags;
- byte gotsig;
byte do_termios;
#if ENABLE_FEATURE_TELNET_TTYPE
char *ttype;
{
char b;
- if (G.gotsig) /* came from line mode... go raw */
+ if (bb_got_signal) /* came from line mode... go raw */
rawmode();
write_str(1, "\r\nConsole escape. Commands are:\r\n\n"
switch (b) {
case 'l':
- if (!G.gotsig) {
+ if (!bb_got_signal) {
do_linemode();
goto rrturn;
}
break;
case 'c':
- if (G.gotsig) {
+ if (bb_got_signal) {
will_charmode();
goto rrturn;
}
write_str(1, "continuing...\r\n");
- if (G.gotsig)
+ if (bb_got_signal)
cookmode();
rrturn:
- G.gotsig = 0;
+ bb_got_signal = 0;
}
return FALSE;
}
-static void fgotsig(int sig)
-{
- G.gotsig = sig;
-}
-
-
static void rawmode(void)
{
if (G.do_termios)
setsockopt(netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
- signal(SIGINT, fgotsig);
+ signal(SIGINT, record_signo);
#ifdef USE_POLL
ufds[0].fd = 0; ufds[1].fd = netfd;
/* timeout */
case -1:
/* error, ignore and/or log something, bay go to loop */
- if (G.gotsig)
+ if (bb_got_signal)
conescape();
else
sleep(1);
struct pollfd pfd[1];
unsigned stamplog;
smallint check; /* = 1; */
- smallint exitsoon;
smallint set_pgrp;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#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; \
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;
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;
}
}
- 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 */