diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2010-12-01 08:51:49 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-12-02 07:47:51 -0500 |
commit | b892b95f0ba494a3e149164695ef58d79dd9fb0c (patch) | |
tree | 3b89577de2fa982d0348a636e8a241cb8f66550e /src/util | |
parent | d8e3d9b5fb5f269ef7a0cf4b70f3ba4c8051429c (diff) | |
download | sssd-b892b95f0ba494a3e149164695ef58d79dd9fb0c.tar.gz sssd-b892b95f0ba494a3e149164695ef58d79dd9fb0c.tar.bz2 sssd-b892b95f0ba494a3e149164695ef58d79dd9fb0c.zip |
Make default SIGTERM and SIGINT handlers use tevent
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/server.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/util/server.c b/src/util/server.c index 39177d38..4767f47d 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")); |