chiark / gitweb /
process: Clear SHUTDOWN hooks in afterfork()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 30 Sep 2014 17:22:14 +0000 (18:22 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 21 Oct 2014 00:07:11 +0000 (01:07 +0100)
That allows child processes to safely use the standard fatal() calls
etc.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
process.c
secnet.h
util.c

index a15e3a6..77fe38e 100644 (file)
--- 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)) {
index ecbc9de..76db603 100644 (file)
--- 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 (file)
--- 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;