summaryrefslogtreecommitdiffstats
path: root/src/sighook.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2025-01-18 15:03:18 -0500
committerTavian Barnes <tavianator@tavianator.com>2025-01-18 15:09:59 -0500
commitb32a43b3a825f1e5062e4d8fe78858f7f1d12f5e (patch)
tree3637b44fbd82b0b06f0b4c1077efa8cb14c3688e /src/sighook.c
parentaf207e702148e5c9ae08047d7a2dce6394653b62 (diff)
downloadbfs-b32a43b3a825f1e5062e4d8fe78858f7f1d12f5e.tar.xz
sighook: Fix up siginit() error paths
Diffstat (limited to 'src/sighook.c')
-rw-r--r--src/sighook.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/sighook.c b/src/sighook.c
index 820044c..fc0db6d 100644
--- a/src/sighook.c
+++ b/src/sighook.c
@@ -573,26 +573,32 @@ static int siginit(int sig) {
return 0;
}
- struct sigsave *save = ALLOC(struct sigsave);
- if (!save) {
+ sigset_t updated = signals;
+ if (sigaddset(&updated, sig) != 0) {
return -1;
}
- save->sig = sig;
- if (sigaction(sig, NULL, &save->action) != 0) {
- free(save);
+ struct sigaction original;
+ if (sigaction(sig, NULL, &original) != 0) {
return -1;
}
- rcu_list_append(&saved, &save->node);
- if (sigaction(sig, &action, NULL) != 0) {
+ struct sigsave *save = ALLOC(struct sigsave);
+ if (!save) {
return -1;
}
- if (sigaddset(&signals, sig) != 0) {
+ save->sig = sig;
+ save->action = original;
+ rcu_list_append(&saved, &save->node);
+
+ if (sigaction(sig, &action, NULL) != 0) {
+ rcu_list_remove(&saved, &save->node);
+ free(save);
return -1;
}
+ signals = updated;
return 0;
}