From b892b95f0ba494a3e149164695ef58d79dd9fb0c Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 1 Dec 2010 08:51:49 -0500 Subject: Make default SIGTERM and SIGINT handlers use tevent --- src/util/server.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/util/server.c') diff --git a/src/util/server.c b/src/util/server.c index 39177d38b..4767f47d7 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -232,6 +232,25 @@ void sig_term(int sig) exit(0); } +static void default_quit(struct tevent_context *ev, + struct tevent_signal *se, + int signum, + int count, + void *siginfo, + void *private_data) +{ +#if HAVE_GETPGRP + static int done_sigterm; + if (done_sigterm == 0 && getpgrp() == getpid()) { + DEBUG(0,("SIGTERM: killing children\n")); + done_sigterm = 1; + kill(-getpgrp(), SIGTERM); + } +#endif + sss_log(SSS_LOG_INFO, "Shutting down"); + exit(0); +} + #ifndef HAVE_PRCTL static void sig_segv_abrt(int sig) { @@ -277,7 +296,6 @@ static void setup_signals(void) BlockSignals(false, SIGTERM); CatchSignal(SIGHUP, sig_hup); - CatchSignal(SIGTERM, sig_term); #ifndef HAVE_PRCTL /* If prctl is not defined on the system, try to handle @@ -392,6 +410,20 @@ int server_setup(const char *name, int flags, return 1; } + /* Set up an event handler for a SIGINT */ + tes = tevent_add_signal(event_ctx, event_ctx, SIGINT, 0, + default_quit, NULL); + if (tes == NULL) { + return EIO; + } + + /* Set up an event handler for a SIGTERM */ + tes = tevent_add_signal(event_ctx, event_ctx, SIGTERM, 0, + default_quit, NULL); + if (tes == NULL) { + return EIO; + } + ctx = talloc(event_ctx, struct main_context); if (ctx == NULL) { DEBUG(0,("Out of memory, aborting!\n")); -- cgit