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>
Thu, 9 Oct 2014 18:29:59 +0000 (19:29 +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 a15e3a6357f385dbd76115283699b7656ade439a..77fe38e3127134077d8cbdbc3e6e460bcefaf942 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 ecbc9de8a502841ff72b1ae42480cb99974100b4..76db6038c9e1ce9433849a1dabcfe609da221788 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 c459f1340a6d406caf528eebf2f777e173ed3a76..12e52085735508950874bacc4af2dcce571a7a66 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;