From 274fce818821d1aa7287dece474cfa5f5016c89f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 30 Sep 2014 18:22:14 +0100 Subject: [PATCH] process: Clear SHUTDOWN hooks in afterfork() That allows child processes to safely use the standard fatal() calls etc. Signed-off-by: Ian Jackson --- process.c | 4 ++++ secnet.h | 1 + util.c | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/process.c b/process.c index a15e3a6..77fe38e 100644 --- a/process.c +++ b/process.c @@ -218,6 +218,10 @@ void afterfork(void) sigset_t done; struct sigaction sa; + clear_phase_hooks(PHASE_SHUTDOWN); + /* Prevents calls to fatal() etc. in the child from running off + and doing a lot of unhelpful things */ + sigemptyset(&done); for (n=sigs; n; n=n->next) if (!sigismember(&done,n->signum)) { diff --git a/secnet.h b/secnet.h index ecbc9de..76db603 100644 --- a/secnet.h +++ b/secnet.h @@ -270,6 +270,7 @@ extern uint32_t current_phase; extern void enter_phase(uint32_t new_phase); void phase_hooks_init(void); /* for main() only */ +void clear_phase_hooks(uint32_t phase); /* for afterfork() */ /* Some features (like netlink 'soft' routes) require that secnet retain root privileges. They should indicate that here when diff --git a/util.c b/util.c index c459f13..12e5208 100644 --- a/util.c +++ b/util.c @@ -227,6 +227,14 @@ void phase_hooks_init(void) LIST_INIT(&hooks[i]); } +void clear_phase_hooks(uint32_t phase) +{ + struct phase_hook *h, *htmp; + LIST_FOREACH_SAFE(h, &hooks[phase], entry, htmp) + free(h); + LIST_INIT(&hooks[phase]); +} + bool_t add_hook(uint32_t phase, hook_fn *fn, void *state) { struct phase_hook *h; -- 2.30.2