Blob Blame History Raw
From a37e7a0ab152fe6c88d49d8c99200f4d26672e63 Mon Sep 17 00:00:00 2001
From: Petr Holasek <pholasek@redhat.com>
Date: Wed, 10 Dec 2014 17:23:30 +0100
Subject: [PATCH] irqbalance signal handling tuning

Added sigaction for SIGTERM, SIGUSR1 and SIGUSR2 using the same handler
like SIGINT, i.e. stop and cleanup after finishing of current balancing
iteration.

Signed-off-by: Petr Holasek <pholasek@redhat.com>
---
 irqbalance.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/irqbalance.c b/irqbalance.c
index 670e688..f22ecfb 100644
--- a/irqbalance.c
+++ b/irqbalance.c
@@ -238,6 +238,15 @@ static void force_rescan(int signum)
 int main(int argc, char** argv)
 {
 	struct sigaction action, hupaction;
+	sigset_t sigset, old_sigset;
+
+	sigemptyset(&sigset);
+	sigaddset(&sigset,SIGINT);
+	sigaddset(&sigset,SIGHUP);
+	sigaddset(&sigset,SIGTERM);
+	sigaddset(&sigset,SIGUSR1);
+	sigaddset(&sigset,SIGUSR2);
+	sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
 
 #ifdef HAVE_GETOPT_LONG
 	parse_command_line(argc, argv);
@@ -290,11 +299,6 @@ int main(int argc, char** argv)
 		HZ = 100;
 	}
 
-	action.sa_handler = handler;
-	sigemptyset(&action.sa_mask);
-	action.sa_flags = 0;
-	sigaction(SIGINT, &action, NULL);
-
 	build_object_tree();
 	if (debug_mode)
 		dump_object_tree();
@@ -324,6 +328,20 @@ int main(int argc, char** argv)
 		}
 	}
 
+	action.sa_handler = handler;
+	sigemptyset(&action.sa_mask);
+	action.sa_flags = 0;
+	sigaction(SIGINT, &action, NULL);
+	sigaction(SIGTERM, &action, NULL);
+	sigaction(SIGUSR1, &action, NULL);
+	sigaction(SIGUSR2, &action, NULL);
+
+	hupaction.sa_handler = force_rescan;
+	sigemptyset(&hupaction.sa_mask);
+	hupaction.sa_flags = 0;
+	sigaction(SIGHUP, &hupaction, NULL);
+
+	sigprocmask(SIG_SETMASK, &old_sigset, NULL);
 
 #ifdef HAVE_LIBCAP_NG
 	// Drop capabilities
@@ -337,11 +355,6 @@ int main(int argc, char** argv)
 	parse_proc_interrupts();
 	parse_proc_stat();
 
-	hupaction.sa_handler = force_rescan;
-	sigemptyset(&hupaction.sa_mask);
-	hupaction.sa_flags = 0;
-	sigaction(SIGHUP, &hupaction, NULL);
-
 	while (keep_going) {
 		sleep_approx(SLEEP_INTERVAL);
 		log(TO_CONSOLE, LOG_INFO, "\n\n\n-----------------------------------------------------------------------------\n");
-- 
2.1.0