summaryrefslogtreecommitdiffstats
path: root/src/monitor
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2012-10-18 10:16:06 +0200
committerJakub Hrozek <jhrozek@redhat.com>2012-11-06 21:23:46 +0100
commit0030538a4559ca15ce6d85e59d3ae8db2ccb79c6 (patch)
tree1a1be981c700cc720887080e22acb8cb25c7b9c2 /src/monitor
parent939f4101c7a0b27133dd79aeb79032cb58307b21 (diff)
downloadsssd-0030538a4559ca15ce6d85e59d3ae8db2ccb79c6.tar.gz
sssd-0030538a4559ca15ce6d85e59d3ae8db2ccb79c6.tar.xz
sssd-0030538a4559ca15ce6d85e59d3ae8db2ccb79c6.zip
exit original process after sssd is initialized
https://fedorahosted.org/sssd/ticket/1357 Neither systemd or our init script use pid file as a notification that sssd is finished initializing. They will continue starting up next service right after the original (not daemonized) sssd process is terminated. If any of the responders fail to start, we will never terminate the original process via signal and "service sssd start" will hang. Thus we take this as an error and terminate the daemon with a non-zero value. This will also terminate the original process and init script or systemd will print failure.
Diffstat (limited to 'src/monitor')
-rw-r--r--src/monitor/monitor.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index f93a8c95c..956e1d4e0 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -157,6 +157,8 @@ struct mt_ctx {
const char *conf_path;
struct sss_sigchild_ctx *sigchld_ctx;
bool pid_file_created;
+ bool is_daemon;
+ pid_t parent_pid;
};
static int start_service(struct mt_svc *mt_svc);
@@ -449,6 +451,28 @@ static int mark_service_as_started(struct mt_svc *svc)
}
ctx->pid_file_created = true;
+
+ /* Initialization is complete, terminate parent process if in daemon
+ * mode. Make sure we send the signal to the right process */
+ if (ctx->is_daemon) {
+ if (ctx->parent_pid <= 1 || ctx->parent_pid != getppid()) {
+ /* the parent process was already terminated */
+ DEBUG(SSSDBG_MINOR_FAILURE, ("Invalid parent pid: %d\n",
+ ctx->parent_pid));
+ goto done;
+ }
+
+ DEBUG(SSSDBG_TRACE_FUNC, ("SSSD is initialized, "
+ "terminating parent process\n"));
+
+ errno = 0;
+ ret = kill(ctx->parent_pid, SIGTERM);
+ if (ret != 0) {
+ ret = errno;
+ DEBUG(SSSDBG_FATAL_FAILURE, ("Unable to terminate parent "
+ "process [%d]: %s\n", ret, strerror(ret)));
+ }
+ }
}
done:
@@ -2647,6 +2671,8 @@ int main(int argc, const char *argv[])
ret = server_setup(MONITOR_NAME, flags, monitor->conf_path, &main_ctx);
if (ret != EOK) return 2;
+ monitor->is_daemon = !opt_interactive;
+ monitor->parent_pid = main_ctx->parent_pid;
monitor->ev = main_ctx->event_ctx;
talloc_steal(main_ctx, monitor);