summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2012-11-01 13:20:43 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-11-06 21:23:39 +0100
commit939f4101c7a0b27133dd79aeb79032cb58307b21 (patch)
treeb4c9f7fab0edc74518bbc78687d75fb689143b6c
parent79bdd5069166d618533d9a7f643f598e760a8cf9 (diff)
downloadsssd-939f4101c7a0b27133dd79aeb79032cb58307b21.tar.gz
sssd-939f4101c7a0b27133dd79aeb79032cb58307b21.tar.xz
sssd-939f4101c7a0b27133dd79aeb79032cb58307b21.zip
make monitor_quit() usable outside signal handler
-rw-r--r--src/monitor/monitor.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index e6da990d2..f93a8c95c 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -1257,14 +1257,8 @@ static int monitor_cleanup(void)
return EOK;
}
-static void monitor_quit(struct tevent_context *ev,
- struct tevent_signal *se,
- int signum,
- int count,
- void *siginfo,
- void *private_data)
+static void monitor_quit(struct mt_ctx *mt_ctx, int ret)
{
- struct mt_ctx *mt_ctx = talloc_get_type(private_data, struct mt_ctx);
struct mt_svc *svc;
pid_t pid;
int status;
@@ -1272,10 +1266,7 @@ static void monitor_quit(struct tevent_context *ev,
int kret;
bool killed;
- DEBUG(8, ("Received shutdown command\n"));
-
- DEBUG(0, ("Monitor received %s: terminating children\n",
- strsignal(signum)));
+ DEBUG(SSSDBG_IMPORTANT_INFO, ("Returned with: %d\n", ret));
/* Kill all of our known children manually */
DLIST_FOR_EACH(svc, mt_ctx->svc_list) {
@@ -1350,7 +1341,24 @@ static void monitor_quit(struct tevent_context *ev,
monitor_cleanup();
- exit(0);
+ exit(ret);
+}
+
+static void monitor_quit_signal(struct tevent_context *ev,
+ struct tevent_signal *se,
+ int signum,
+ int count,
+ void *siginfo,
+ void *private_data)
+{
+ struct mt_ctx *mt_ctx = talloc_get_type(private_data, struct mt_ctx);
+
+ DEBUG(SSSDBG_TRACE_INTERNAL, ("Received shutdown command\n"));
+
+ DEBUG(SSSDBG_IMPORTANT_INFO, ("Monitor received %s: terminating "
+ "children\n", strsignal(signum)));
+
+ monitor_quit(mt_ctx, 0);
}
static void signal_res_init(struct mt_ctx *monitor)
@@ -2026,14 +2034,14 @@ int monitor_process_init(struct mt_ctx *ctx,
/* Set up an event handler for a SIGINT */
BlockSignals(false, SIGINT);
tes = tevent_add_signal(ctx->ev, ctx, SIGINT, 0,
- monitor_quit, ctx);
+ monitor_quit_signal, ctx);
if (tes == NULL) {
return EIO;
}
/* Set up an event handler for a SIGTERM */
tes = tevent_add_signal(ctx->ev, ctx, SIGTERM, 0,
- monitor_quit, ctx);
+ monitor_quit_signal, ctx);
if (tes == NULL) {
return EIO;
}
@@ -2412,6 +2420,7 @@ static void service_startup_handler(struct tevent_context *ev,
static void mt_svc_exit_handler(int pid, int wait_status, void *pvt)
{
struct mt_svc *svc = talloc_get_type(pvt, struct mt_svc);
+ struct mt_ctx *mt_ctx = svc->mt_ctx;
time_t now = time(NULL);
if WIFEXITED(wait_status) {
@@ -2442,6 +2451,9 @@ static void mt_svc_exit_handler(int pid, int wait_status, void *pvt)
DEBUG(SSSDBG_FATAL_FAILURE,
("Process [%s], definitely stopped!\n", svc->name));
talloc_free(svc);
+
+ /* exit with error */
+ monitor_quit(mt_ctx, 1);
return;
}