[Sheepdog] [PATCH] Cleanup the log function
huxinwei
huxinwei at huawei.com
Tue Mar 6 10:40:21 CET 2012
Hi List,
The log_sigsegv function in logger.c actually serves two purposes.
1, the logger itself exit on illegal memory access.
2, the sheep exit, which makes the kernel deliver a SIGSEGV to the logger process
I think it'll be a good idea to make distinguish between these 2.
Please help to review and make comments.
Thanks.
Signed-off-by: Xinwei Hu <huxinwei at huawei.com>
diff --git a/lib/logger.c b/lib/logger.c
index 5be035a..d5eb453 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -353,9 +353,14 @@ static void log_flush(void)
}
}
-static void log_sigsegv(void)
+static void log_sigexit(int signo)
{
- vprintf(SDOG_ERR, "logger pid %d exiting abnormally\n", getpid());
+ 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");
log_flush();
closelog();
free_logarea();
@@ -419,13 +424,15 @@ int log_init(char *program_name, int size, int is_daemon, int level, char *outfi
exit(1);
}
+ pid = getppid();
/* flush on daemon's crash */
- sa_new.sa_handler = (void*)log_sigsegv;
+ sa_new.sa_handler = (void*)log_sigexit;
sigemptyset(&sa_new.sa_mask);
sa_new.sa_flags = 0;
sigaction(SIGSEGV, &sa_new, &sa_old );
+ sigaction(SIGHUP, &sa_new, &sa_old );
- prctl(PR_SET_PDEATHSIG, SIGSEGV);
+ prctl(PR_SET_PDEATHSIG, SIGHUP);
while (la->active) {
log_flush();
More information about the sheepdog
mailing list