aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-10-10 05:26:02 -0500
committerRob Landley <rob@landley.net>2018-10-10 05:26:02 -0500
commitc276b8a8c2a5181558b976b9cb1d60a0180d560e (patch)
treef2f6cd6bff76573b2a94ade1d0cdadce654a323a
parent1f73aace0feb60ce1b200e7bf8e8339c1e2994fa (diff)
downloadtoybox-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.c4
-rw-r--r--lib/lib.h1
-rw-r--r--lib/password.c3
-rw-r--r--lib/xwrap.c8
4 files changed, 13 insertions, 3 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 17a4f483..9deadad9 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -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;
diff --git a/lib/lib.h b/lib/lib.h
index 18eb0509..136cdab5 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -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);
+}