It seems that current method of detecting sheep's death from logger process sometimes fails. The SIGHUP is caught as a request of log rotation. The problem comes from that SIGHUP is used for both of log rotation request and death detection, and getppid() somestimes returns value not equal to 1 when SIGHUP which is caused by the death rises. This patch lets logger detect death of sheep viapolling. The detection mechanism is simple: calling getppid() at the tail of the log flush loop every time. It would be enough for practical death detection. Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp> --- lib/logger.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/logger.c b/lib/logger.c index 3b5607b..d2c10dc 100644 --- a/lib/logger.c +++ b/lib/logger.c @@ -545,17 +545,6 @@ static void crash_handler(int signo) static void sighup_handler(int signo) { - if (getppid() == 1) - /* - * My parent (sheep process) is dead. This SIGHUP is sent - * because of prctl(PR_SET_PDEATHSIG, SIGHUP) - */ - return crash_handler(signo); - - /* - * My parent sheep process is still alive, this SIGHUP is a request - * for log rotation. - */ rotate_log(); } @@ -591,8 +580,6 @@ static void logger(char *log_dir, char *outfile) install_crash_handler(crash_handler); install_sighandler(SIGHUP, sighup_handler, false); - prctl(PR_SET_PDEATHSIG, SIGHUP); - /* * we need to check the aliveness of the sheep process since * it could die before the logger call prctl. @@ -620,6 +607,15 @@ static void logger(char *log_dir, char *outfile) unblock_sighup(); + if (getppid() == 1) { + /* My parent (sheep process) is dead. */ + log_flush(); + closelog(); + free_logarea(); + + exit(1); + } + sleep(1); } -- 1.7.10.4 |