summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-12-01 08:51:49 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-12-02 13:17:58 -0500
commit4e6cc423196c67ee34701db5089920f1df0d4b00 (patch)
tree2457b8c6c8089feaf4e5f4cf7d6b309a5dc40f25
parent5cc5c27ab94a0be6baa7d71cd0ce3d3b341cf73a (diff)
downloadsssd2-4e6cc423196c67ee34701db5089920f1df0d4b00.tar.gz
sssd2-4e6cc423196c67ee34701db5089920f1df0d4b00.tar.xz
sssd2-4e6cc423196c67ee34701db5089920f1df0d4b00.zip
Make default SIGTERM and SIGINT handlers use tevent
-rw-r--r--src/util/server.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/util/server.c b/src/util/server.c
index 446e2ea6..c177a5dd 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)
{
@@ -274,7 +293,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
@@ -389,6 +407,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"));