summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-11-09 16:07:06 -0500
committerJakub Hrozek <jhrozek@redhat.com>2013-11-12 11:24:58 +0100
commit3242dd4a49c3869c9b066a63afb81cebf1a35b7d (patch)
tree3e345e445e651f01511fa81c4a365588cbcaf377 /src/util
parent27712b5a46e3b579b9d03e363a7d0769e8c307fc (diff)
downloadsssd-3242dd4a49c3869c9b066a63afb81cebf1a35b7d.tar.gz
sssd-3242dd4a49c3869c9b066a63afb81cebf1a35b7d.tar.xz
sssd-3242dd4a49c3869c9b066a63afb81cebf1a35b7d.zip
Signals: Refactor termination of processes
sig_term() was never used as a real signal handler, but only called by tevent signal handlers in the kerberos and ldap children. Also the same code was duplicated with separate local guard variables in other functions. Unify orderly termination handling, between all these functions.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/server.c36
-rw-r--r--src/util/util.h2
2 files changed, 11 insertions, 27 deletions
diff --git a/src/util/server.c b/src/util/server.c
index 11569b937..b2fad1168 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -237,18 +237,18 @@ int pidfile(const char *path, const char *name)
return 0;
}
-void sig_term(int sig)
+void orderly_shutdown(int status)
{
#if HAVE_GETPGRP
- static int done_sigterm;
- if (done_sigterm == 0 && getpgrp() == getpid()) {
+ static int sent_sigterm;
+ if (sent_sigterm == 0 && getpgrp() == getpid()) {
DEBUG(SSSDBG_FATAL_FAILURE, ("SIGTERM: killing children\n"));
- done_sigterm = 1;
+ sent_sigterm = 1;
kill(-getpgrp(), SIGTERM);
}
#endif
- sss_log(SSS_LOG_INFO, "Shutting down");
- exit(0);
+ if (status == 0) sss_log(SSS_LOG_INFO, "Shutting down");
+ exit(status);
}
static void default_quit(struct tevent_context *ev,
@@ -258,31 +258,15 @@ static void default_quit(struct tevent_context *ev,
void *siginfo,
void *private_data)
{
-#if HAVE_GETPGRP
- static int done_sigterm;
- if (done_sigterm == 0 && getpgrp() == getpid()) {
- DEBUG(SSSDBG_FATAL_FAILURE, ("SIGTERM: killing children\n"));
- done_sigterm = 1;
- kill(-getpgrp(), SIGTERM);
- }
-#endif
- sss_log(SSS_LOG_INFO, "Shutting down");
- exit(0);
+ orderly_shutdown(0);
}
#ifndef HAVE_PRCTL
static void sig_segv_abrt(int sig)
{
-#if HAVE_GETPGRP
- static int done;
- if (done == 0 && getpgrp() == getpid()) {
- DEBUG(SSSDBG_FATAL_FAILURE, ("%s: killing children\n",
- strsignal(sig)));
- done = 1;
- kill(-getpgrp(), SIGTERM);
- }
-#endif /* HAVE_GETPGRP */
- exit(1);
+ DEBUG(SSSDBG_FATAL_FAILURE,
+ ("Received signal %s, shutting down\n", strsignal(sig)));
+ orderly_shutdown(1);
}
#endif /* HAVE_PRCTL */
diff --git a/src/util/util.h b/src/util/util.h
index 581ba6fec..4c0e75f12 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -298,7 +298,7 @@ int server_setup(const char *name, int flags,
const char *conf_entry,
struct main_context **main_ctx);
void server_loop(struct main_context *main_ctx);
-void sig_term(int sig);
+void orderly_shutdown(int status);
/* from signal.c */
#include <signal.h>