[CRIU] [PATCH 2/2] service: rotate log by SIGUSR1

Ruslan Kuprieiev kupruser at gmail.com
Mon Feb 10 06:02:08 PST 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 cr-service.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/cr-service.c b/cr-service.c
index 26dd3e2..2a75178 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -489,12 +489,21 @@ static void reap_worker(int signo)
 	}
 }
 
-static int setup_sigchld_handler()
+static void rotate_log(int signo)
+{
+	pr_info("Rotating log.\n");
+
+	if (log_rotate())
+		exit(1);
+}
+
+static int setup_signal_handlers()
 {
 	struct sigaction action;
 
 	sigemptyset(&action.sa_mask);
 	sigaddset(&action.sa_mask, SIGCHLD);
+	sigaddset(&action.sa_mask, SIGUSR1);
 	action.sa_handler	= reap_worker;
 	action.sa_flags		= SA_RESTART;
 
@@ -503,15 +512,23 @@ static int setup_sigchld_handler()
 		return -1;
 	}
 
+	action.sa_handler	= rotate_log;
+
+	if (sigaction(SIGUSR1, &action, NULL)) {
+		pr_perror("Can't setup SIGUSR1 handler");
+		return -1;
+	}
+
 	return 0;
 }
 
-static int restore_sigchld_handler()
+static int restore_signal_handlers()
 {
 	struct sigaction action;
 
 	sigemptyset(&action.sa_mask);
 	sigaddset(&action.sa_mask, SIGCHLD);
+	sigaddset(&action.sa_mask, SIGUSR1);
 	action.sa_handler	= SIG_DFL;
 	action.sa_flags		= SA_RESTART;
 
@@ -596,7 +613,7 @@ int cr_service(bool daemon_mode)
 		}
 	}
 
-	if (setup_sigchld_handler())
+	if (setup_signal_handlers())
 		goto err;
 
 	while (1) {
@@ -615,7 +632,7 @@ int cr_service(bool daemon_mode)
 		if (child_pid == 0) {
 			int ret;
 
-			if (restore_sigchld_handler())
+			if (restore_signal_handlers())
 				exit(1);
 
 			close(server_fd);
-- 
1.8.3.2



More information about the CRIU mailing list