[sheepdog-users] [PATCH stable-0.7 1/3] logger: avoid using SIGHUP for detecting death of sheep

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Jan 27 11:54:33 CET 2014


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>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 lib/logger.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/lib/logger.c b/lib/logger.c
index 157cf12..25da92a 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -541,17 +541,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();
 }
 
@@ -587,8 +576,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.
@@ -616,6 +603,10 @@ static void logger(char *log_dir, char *outfile)
 
 		unblock_sighup();
 
+		if (getppid() == 1)
+			/* My parent (sheep process) is dead. */
+			break;
+
 		sleep(1);
 	}
 
-- 
1.7.10.4




More information about the sheepdog-users mailing list