diff options
author | Rob Landley <rob@landley.net> | 2018-10-10 05:26:02 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-10-10 05:26:02 -0500 |
commit | c276b8a8c2a5181558b976b9cb1d60a0180d560e (patch) | |
tree | f2f6cd6bff76573b2a94ade1d0cdadce654a323a | |
parent | 1f73aace0feb60ce1b200e7bf8e8339c1e2994fa (diff) | |
download | toybox-c276b8a8c2a5181558b976b9cb1d60a0180d560e.tar.gz |
Add xsignal_flags() and more consistently use xsignal() instead of signal().
xsignal() wraps sigaction() giving control of SA_RESTART behavior and such.
-rw-r--r-- | lib/lib.c | 4 | ||||
-rw-r--r-- | lib/lib.h | 1 | ||||
-rw-r--r-- | lib/password.c | 3 | ||||
-rw-r--r-- | lib/xwrap.c | 8 |
4 files changed, 13 insertions, 3 deletions
@@ -854,7 +854,9 @@ void sigatexit(void *handler) int i; for (i=0; signames[i].num != SIGCHLD; i++) - signal(signames[i].num, handler ? exit_signal : SIG_DFL); + if (signames[i].num != SIGKILL) + xsignal(signames[i].num, handler ? exit_signal : SIG_DFL); + if (handler) { al = xmalloc(sizeof(struct arg_list)); al->next = toys.xexit; @@ -175,6 +175,7 @@ long xparsetime(char *arg, long units, long *fraction); void xpidfile(char *name); void xregcomp(regex_t *preg, char *rexec, int cflags); char *xtzset(char *new); +void xsignal_flags(int signal, void *handler, int flags); void xsignal(int signal, void *handler); // lib.c diff --git a/lib/password.c b/lib/password.c index a02bc542..b9cc1346 100644 --- a/lib/password.c +++ b/lib/password.c @@ -53,7 +53,8 @@ int read_password(char *buf, int buflen, char *mesg) struct sigaction sa, oldsa; int i, ret = 1; - // NOP signal handler to return from the read + // NOP signal handler to return from the read. Use sigaction() instead + // of xsignal() because we want to restore the old handler afterwards. memset(&sa, 0, sizeof(sa)); sa.sa_handler = generic_signal; sigaction(SIGINT, &sa, &oldsa); diff --git a/lib/xwrap.c b/lib/xwrap.c index 3e0f57e4..7276151f 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -841,12 +841,18 @@ char *xtzset(char *new) } // Set a signal handler -void xsignal(int signal, void *handler) +void xsignal_flags(int signal, void *handler, int flags) { struct sigaction *sa = (void *)libbuf; memset(sa, 0, sizeof(struct sigaction)); sa->sa_handler = handler; + sa->sa_flags = flags; if (sigaction(signal, sa, 0)) perror_exit("xsignal %d", signal); } + +void xsignal(int signal, void *handler) +{ + xsignal_flags(signal, handler, 0); +} |