Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- This approach looks better. We can also handle the crash of sheep. lib/logger.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/lib/logger.c b/lib/logger.c index 15699f0..5d0cc8d 100644 --- a/lib/logger.c +++ b/lib/logger.c @@ -27,6 +27,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> +#include <sys/prctl.h> #include "logger.h" @@ -361,6 +362,15 @@ static void log_flush(void) } } +static void log_sigsegv(void) +{ + vprintf(SDOG_ERR "sheep logger exits abnormally, pid:%d\n", getpid()); + log_flush(); + closelog(); + free_logarea(); + exit(1); +} + int log_init(char *program_name, int size, int is_daemon, int level, char *outfile) { log_level = level; @@ -420,11 +430,13 @@ int log_init(char *program_name, int size, int is_daemon, int level, char *outfi } /* flush on daemon's crash */ - sa_new.sa_handler = (void*)log_flush; + sa_new.sa_handler = (void*)log_sigsegv; sigemptyset(&sa_new.sa_mask); sa_new.sa_flags = 0; sigaction(SIGSEGV, &sa_new, &sa_old ); + prctl(PR_SET_PDEATHSIG, SIGSEGV); + while (la->active) { log_flush(); sleep(1); -- 1.7.2.5 |