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

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Dec 20 10:41:12 CET 2012


This patch makes signal event (rise of SIGTERM) as a highest
prioritized event and lets signal_handler() return EVENT_RET_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>
---
 sheep/sheep.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/sheep/sheep.c b/sheep/sheep.c
index c3f4200..8af0192 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_RET_DONE;
 
 	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_RET_BREAK;
 		break;
 	default:
 		eprintf("signal %d unhandled\n", siginfo.ssi_signo);
 		break;
 	}
 
-	return EVENT_RET_DONE;
+	return e_ret;
 }
 
 static int init_signal(void)
-- 
1.7.2.5




More information about the sheepdog mailing list