aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-05-19 02:05:36 -0500
committerRob Landley <rob@landley.net>2020-05-19 02:05:36 -0500
commitfa8d18a757fa4454a8ad25f5e0fb5e49555e8435 (patch)
treed90f1383af0a8bd91adee37ce6bb3d8471ed4259 /lib
parent2d95e03b0e2dcc8bcb23a21feebff84bccf1084c (diff)
downloadtoybox-fa8d18a757fa4454a8ad25f5e0fb5e49555e8435.tar.gz
xsignal_all_killers() should install the handler given to it, and do some
refactoring while I was looking at the codepath.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c13
-rw-r--r--lib/portability.c6
2 files changed, 8 insertions, 11 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 4fa358c0..71ce1fac 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -890,18 +890,15 @@ void exit_signal(int sig)
// adds the handlers to a list, to be called in order.
void sigatexit(void *handler)
{
- xsignal_all_killers(handler ? exit_signal : SIG_DFL);
+ struct arg_list *al = 0;
+ xsignal_all_killers(handler ? exit_signal : SIG_DFL);
if (handler) {
- struct arg_list *al = xmalloc(sizeof(struct arg_list));
-
+ al = xmalloc(sizeof(struct arg_list));
al->next = toys.xexit;
al->arg = handler;
- toys.xexit = al;
- } else {
- llist_traverse(toys.xexit, free);
- toys.xexit = 0;
- }
+ } else llist_traverse(toys.xexit, free);
+ toys.xexit = al;
}
// Output a nicely formatted 80-column table of all the signals.
diff --git a/lib/portability.c b/lib/portability.c
index 26b854d6..8b8f0f3b 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -452,9 +452,9 @@ void xsignal_all_killers(void *handler)
{
int i;
- for (i=0; signames[i].num != SIGCHLD; i++)
- if (signames[i].num != SIGKILL)
- xsignal(signames[i].num, handler ? exit_signal : SIG_DFL);
+ if (!handler) handler = SIG_DFL;
+ for (i = 0; signames[i].num != SIGCHLD; i++)
+ if (signames[i].num != SIGKILL) xsignal(signames[i].num, handler);
}
// Convert a string like "9", "KILL", "SIGHUP", or "SIGRTMIN+2" to a number.