MEDIUM: signal: signal_unregister() removes every handlers
The new function signal_unregister() removes every handlers assigned to
a signal. Once the handler list of the signal is empty, the signal is
ignored with SIG_IGN.
diff --git a/include/proto/signal.h b/include/proto/signal.h
index b61a527..0806d04 100644
--- a/include/proto/signal.h
+++ b/include/proto/signal.h
@@ -32,6 +32,7 @@
struct sig_handler *signal_register_task(int sig, struct task *task, int reason);
void signal_unregister_handler(struct sig_handler *handler);
void signal_unregister_target(int sig, void *target);
+void signal_unregister(int sig);
void haproxy_unblock_signals();
static inline void signal_process_queue()
diff --git a/src/signal.c b/src/signal.c
index 75d5c65..9387728 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -254,3 +254,23 @@
}
}
}
+
+/*
+ * Immedialtely unregister every handler assigned to a signal <sig>.
+ * Once the handler list is empty, the signal is ignored with SIG_IGN.
+ */
+
+void signal_unregister(int sig)
+{
+ struct sig_handler *sh, *shb;
+
+ if (sig < 0 || sig >= MAX_SIGNAL)
+ return;
+
+ list_for_each_entry_safe(sh, shb, &signal_state[sig].handlers, list) {
+ LIST_DEL(&sh->list);
+ pool_free(pool_head_sig_handlers, sh);
+ }
+
+ signal(sig, SIG_IGN);
+}