diff options
-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); +} |