6aed92
From b5b92669c32b50b2f96a3ae53d4222d6cb3d1287 Mon Sep 17 00:00:00 2001
6aed92
From: Nikolai Kondrashov <nikolai.kondrashov@redhat.com>
6aed92
Date: Tue, 28 Oct 2014 15:57:56 +0200
6aed92
Subject: [PATCH 1/1] Ignore SIGTERM when firing stop and signal.term
6aed92
6aed92
Move firing "server.stop" and "server.signal.term" triggers beyond
6aed92
setting SIGTERM action to SIG_IGN in main().
6aed92
6aed92
This way handler commands for these triggers don't receive SIGTERM with
6aed92
the rest of the process group and don't possibly terminate before doing
6aed92
their work. E.g. snmptrap manages to send the notifications.
6aed92
---
6aed92
 src/main/process.c |  1 -
6aed92
 src/main/radiusd.c | 10 ++++++++--
6aed92
 2 files changed, 8 insertions(+), 3 deletions(-)
6aed92
6aed92
diff --git a/src/main/process.c b/src/main/process.c
6aed92
index 7e1a51e..f427205 100644
6aed92
--- a/src/main/process.c
6aed92
+++ b/src/main/process.c
6aed92
@@ -4536,7 +4536,6 @@ static void handle_signal_self(int flag)
6aed92
 			fr_event_loop_exit(el, 1);
6aed92
 		} else {
6aed92
 			INFO("Signalled to terminate");
6aed92
-			exec_trigger(NULL, NULL, "server.signal.term", true);
6aed92
 			fr_event_loop_exit(el, 2);
6aed92
 		}
6aed92
 
6aed92
diff --git a/src/main/radiusd.c b/src/main/radiusd.c
6aed92
index 620d7d4..86c7013 100644
6aed92
--- a/src/main/radiusd.c
6aed92
+++ b/src/main/radiusd.c
6aed92
@@ -592,8 +592,6 @@ int main(int argc, char *argv[])
6aed92
 		INFO("Exiting normally");
6aed92
 	}
6aed92
 
6aed92
-	exec_trigger(NULL, NULL, "server.stop", false);
6aed92
-
6aed92
 	/*
6aed92
 	 *	Ignore the TERM signal: we're
6aed92
 	 *	about to die.
6aed92
@@ -601,6 +599,14 @@ int main(int argc, char *argv[])
6aed92
 	signal(SIGTERM, SIG_IGN);
6aed92
 
6aed92
 	/*
6aed92
+	 * Fire signal and stop triggers after ignoring SIGTERM, so handlers are
6aed92
+	 * not killed with the rest of the process group, below.
6aed92
+	 */
6aed92
+	if (status == 2)
6aed92
+		exec_trigger(NULL, NULL, "server.signal.term", true);
6aed92
+	exec_trigger(NULL, NULL, "server.stop", false);
6aed92
+
6aed92
+	/*
6aed92
 	 *	Send a TERM signal to all
6aed92
 	 *	associated processes
6aed92
 	 *	(including us, which gets
6aed92
-- 
6aed92
2.1.1
6aed92