From 1f56f361c23e91a681446c025070ab91e4b6eb94 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 9 Sep 2009 11:09:09 -0400 Subject: [PATCH 1/3] Daemonize the SSSD only after the monitor is configured If there are failures during configuration, the SSSD should exit with the appropriate error code so that the init script will report "FAILED" This also moves the pidfile creation into the monitor's main function since it has to be created after the fork or restarts will fail. --- server/monitor/monitor.c | 14 ++++++++++++++ server/util/server.c | 16 +--------------- server/util/util.h | 2 ++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c index 86b2364..5b8ba21 100644 --- a/server/monitor/monitor.c +++ b/server/monitor/monitor.c @@ -2393,6 +2393,20 @@ int main(int argc, const char *argv[]) if (ret != EOK) return 3; talloc_free(config_file); + if (flags & FLAGS_DAEMON) { + DEBUG(3,("Becoming a daemon.\n")); + become_daemon(true); + } + + if (flags & FLAGS_PID_FILE) { + ret = pidfile(PID_PATH, "sssd"); + if (ret != EOK) { + DEBUG(0, ("Error creating pidfile! (%d [%s])\n", + ret, strerror(ret))); + return ret; + } + } + /* loop on main */ server_loop(main_ctx); diff --git a/server/util/server.c b/server/util/server.c index d20a823..402524b 100644 --- a/server/util/server.c +++ b/server/util/server.c @@ -47,7 +47,7 @@ static void close_low_fds(bool stderr_too) int i; close(0); - close(1); + close(1); if (stderr_too) close(2); @@ -312,20 +312,6 @@ int server_setup(const char *name, int flags, so set our umask to 0177 */ umask(0177); - if (flags & FLAGS_DAEMON) { - DEBUG(3,("Becoming a daemon.\n")); - become_daemon(true); - } - - if (flags & FLAGS_PID_FILE) { - ret = pidfile(PID_PATH, name); - if (ret != EOK) { - DEBUG(0, ("Error creating pidfile! (%d [%s])\n", - ret, strerror(ret))); - return ret; - } - } - /* Set up locale */ setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); diff --git a/server/util/util.h b/server/util/util.h index 93e5dc9..0bb8c61 100644 --- a/server/util/util.h +++ b/server/util/util.h @@ -113,6 +113,8 @@ struct main_context { }; int die_if_parent_died(void); +void become_daemon(bool Fork); +int pidfile(const char *path, const char *name); int server_setup(const char *name, int flags, const char *conf_entry, struct main_context **main_ctx); -- 1.6.2.5