[Sheepdog] [PATCH 1/3] logger: improve death messages

Christoph Hellwig hch at infradead.org
Wed Apr 25 08:58:53 CEST 2012


Make the fact more clear that a SIGHUP to the logger means that the
sheep daemon died a horrible dead.  Also improve the log messag for
a logger death a little, and rename log_sigexit so the name describes
its function better.

Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: sheepdog/lib/logger.c
===================================================================
--- sheepdog.orig/lib/logger.c	2012-04-21 08:09:51.987584773 +0200
+++ sheepdog/lib/logger.c	2012-04-25 08:34:15.520023896 +0200
@@ -382,14 +382,18 @@ static notrace void log_flush(void)
 	}
 }
 
-static notrace void log_sigexit(int signo)
+static notrace void crash_handler(int signo)
 {
-	if (signo == SIGSEGV)
-		vprintf(SDOG_ERR, "logger pid %d exiting abnormally\n", getpid());
-	else if (signo == SIGHUP)
-		vprintf(SDOG_ERR, "sheep pid %d exiting.\n", pid);
-	else
-		vprintf(SDOG_ERR, "something wrong.\n");
+	if (signo == SIGSEGV) {
+		vprintf(SDOG_ERR, "logger pid %d segfaulted.\n",
+			getpid());
+	} else if (signo == SIGHUP) {
+		vprintf(SDOG_ERR, "sheep pid %d exited unexpectedly.\n", pid);
+	} else {
+		vprintf(SDOG_ERR, "logger pid %d got unexpected signal %d.\n",
+			pid, signo);
+	}
+
 	log_flush();
 	closelog();
 	free_logarea();
@@ -457,13 +461,13 @@ notrace int log_init(char *program_name,
 			exit(1);
 		}
 
-		pid = getppid();
-		/* flush on daemon's crash */
-		sa_new.sa_handler = (void*)log_sigexit;
-		sigemptyset(&sa_new.sa_mask);
+		/* flush when either the logger or its parent dies */
+		sa_new.sa_handler = crash_handler;
 		sa_new.sa_flags = 0;
-		sigaction(SIGSEGV, &sa_new, &sa_old );
-		sigaction(SIGHUP, &sa_new, &sa_old );
+		sigemptyset(&sa_new.sa_mask);
+
+		sigaction(SIGSEGV, &sa_new, &sa_old);
+		sigaction(SIGHUP, &sa_new, &sa_old);
 
 		prctl(PR_SET_PDEATHSIG, SIGHUP);
 



More information about the sheepdog mailing list