summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-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 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"));