Ignore SIGTERM when firing stop and signal.term
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Tue, 28 Oct 2014 13:57:56 +0000 (15:57 +0200)
committerNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Tue, 28 Oct 2014 15:20:58 +0000 (17:20 +0200)
Move firing "server.stop" and "server.signal.term" triggers beyond
setting SIGTERM action to SIG_IGN in main().

This way handler commands for these triggers don't receive SIGTERM with
the rest of the process group and don't possibly terminate before doing
their work. E.g. snmptrap manages to send the notifications.

src/main/process.c
src/main/radiusd.c

index 04d442b..d424e88 100644 (file)
@@ -4680,7 +4680,6 @@ static void handle_signal_self(int flag)
                        fr_event_loop_exit(el, 1);
                } else {
                        INFO("Signalled to terminate");
-                       exec_trigger(NULL, NULL, "server.signal.term", true);
                        fr_event_loop_exit(el, 2);
                }
 
index fe8057d..909eb0c 100644 (file)
@@ -594,8 +594,6 @@ int main(int argc, char *argv[])
                INFO("Exiting normally");
        }
 
-       exec_trigger(NULL, NULL, "server.stop", false);
-
        /*
         *      Ignore the TERM signal: we're
         *      about to die.
@@ -603,6 +601,14 @@ int main(int argc, char *argv[])
        signal(SIGTERM, SIG_IGN);
 
        /*
+        * Fire signal and stop triggers after ignoring SIGTERM, so handlers are
+        * not killed with the rest of the process group, below.
+        */
+       if (status == 2)
+               exec_trigger(NULL, NULL, "server.signal.term", true);
+       exec_trigger(NULL, NULL, "server.stop", false);
+
+       /*
         *      Send a TERM signal to all
         *      associated processes
         *      (including us, which gets