summaryrefslogtreecommitdiffstats
path: root/src/util/server.c
diff options
context:
space:
mode:
authorOndrej Kos <okos@redhat.com>2013-06-19 14:05:00 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-06-25 10:42:36 +0200
commit1554077521ea202bc886d6483b72e5ebdc10c520 (patch)
treedae1a3e2d542da0cb0a1c10965b2d7fac7505fbf /src/util/server.c
parent8adef6fcff7db7b40efa242b147641ffa2981fb0 (diff)
downloadsssd-1554077521ea202bc886d6483b72e5ebdc10c520.tar.gz
sssd-1554077521ea202bc886d6483b72e5ebdc10c520.tar.xz
sssd-1554077521ea202bc886d6483b72e5ebdc10c520.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/util/server.c')
-rw-r--r--src/util/server.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/util/server.c b/src/util/server.c
index 1e8b148d..41c0d97a 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -25,6 +25,7 @@
#define _GNU_SOURCE
#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
@@ -67,18 +68,43 @@ static void close_low_fds(void)
#endif
}
+static void deamon_parent_sigterm(int sig)
+{
+ _exit(0);
+}
+
/**
Become a daemon, discarding the controlling terminal.
**/
void become_daemon(bool Fork)
{
- int ret;
+ pid_t pid;
+ int status;
+ int ret;
if (Fork) {
- if (fork()) {
- _exit(0);
- }
+ pid = fork();
+ if (pid != 0) {
+ /* Terminate parent process on demand so we can hold systemd
+ * or initd from starting next service until sssd in initialized.
+ * We use signals directly here because we don't have a tevent
+ * context yet. */
+ CatchSignal(SIGTERM, deamon_parent_sigterm);
+
+ /* or exit when sssd monitor is terminated */
+ waitpid(pid, &status, 0);
+
+ /* return error if we didn't exited normally */
+ ret = 1;
+
+ if (WIFEXITED(status)) {
+ /* but return our exit code otherwise */
+ ret = WEXITSTATUS(status);
+ }
+
+ _exit(ret);
+ }
}
/* detach from the terminal */
@@ -430,6 +456,7 @@ int server_setup(const char *name, int flags,
return ENOMEM;
}
+ ctx->parent_pid = getppid();
ctx->event_ctx = event_ctx;
conf_db = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);