[sheepdog] [PATCH v2 2/2] sheep: break event loop when killed with SIGTERM

Hitoshi Mitake h.mitake at gmail.com
Fri Dec 21 18:23:02 CET 2012


From: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

This patch makes signal event (rise of SIGTERM) as a highest
prioritized event and lets signal_handler() return EVENT_LOOP_BREAK.
So sheep can immediately exit after receiving the signal.

This can enshort a time period of sys->state == SD_STATUS_KILLED.

Cc: Liu Yuan <tailai.ly at taobao.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v2: use new enum name
8<---
 sheep/sheep.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/sheep/sheep.c b/sheep/sheep.c
index b07ba94..05fe239 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -127,6 +127,7 @@ static enum event_ret signal_handler(int listen_fd, int events, void *data)
 {
 	struct signalfd_siginfo siginfo;
 	int ret;
+	enum event_ret e_ret = EVENT_LOOP_NOP;
 
 	ret = read(sigfd, &siginfo, sizeof(siginfo));
 	assert(ret == sizeof(siginfo));
@@ -134,13 +135,14 @@ static enum event_ret signal_handler(int listen_fd, int events, void *data)
 	switch (siginfo.ssi_signo) {
 	case SIGTERM:
 		sys->status = SD_STATUS_KILLED;
+		e_ret = EVENT_LOOP_BREAK;
 		break;
 	default:
 		eprintf("signal %d unhandled\n", siginfo.ssi_signo);
 		break;
 	}
 
-	return EVENT_LOOP_NOP;
+	return e_ret;
 }
 
 static int init_signal(void)
-- 
1.7.5.1




More information about the sheepdog mailing list