>From 06a33ecc7c7f8338ff588c545146693548e48d78 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 3 Oct 2012 16:23:11 +0200 Subject: [PATCH] Check for existing pidfile before starting the providers After we switched to writing pidfile after the responders started, we forgot that starting a second SSSD instance would first overwrite the pipes and sockets and only then the SSSD would find out there already is a pidfile. This patch checks for existing pidfile before proceeding with startup. --- src/monitor/monitor.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index 920d01c0d1bbf9153d80ebf7bfab9387646e4ec6..e0c196a4e9913572a951c00628d667a287b9a755 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -65,7 +65,8 @@ #define MONITOR_DEF_FORCE_TIME 60 /* name of the monitor server instance */ -#define MONITOR_NAME "sssd" +#define MONITOR_NAME "sssd" +#define SSSD_PIDFILE_PATH PID_PATH"/"MONITOR_NAME".pid" /* Special value to leave the Kerberos Replay Cache set to use * the libkrb5 defaults @@ -1230,29 +1231,17 @@ static void monitor_hup(struct tevent_context *ev, static int monitor_cleanup(void) { - char *file; int ret; - TALLOC_CTX *tmp_ctx; - - tmp_ctx = talloc_new(NULL); - if (!tmp_ctx) return ENOMEM; - - file = talloc_asprintf(tmp_ctx, "%s/%s.pid", PID_PATH, "sssd"); - if (file == NULL) { - return ENOMEM; - } errno = 0; - ret = unlink(file); + ret = unlink(SSSD_PIDFILE_PATH); if (ret == -1) { ret = errno; - DEBUG(0, ("Error removing pidfile! (%d [%s])\n", - ret, strerror(ret))); - talloc_free(file); - return errno; + DEBUG(SSSDBG_FATAL_FAILURE, + ("Error removing pidfile! (%d [%s])\n", ret, strerror(ret))); + return ret; } - talloc_free(file); return EOK; } @@ -2596,6 +2585,15 @@ int main(int argc, const char *argv[]) "netgroup nsswitch maps."); } + /* Check if the SSSD is already running */ + ret = check_file(SSSD_PIDFILE_PATH, 0, 0, 0600, CHECK_REG, NULL, false); + if (ret == EOK) { + DEBUG(SSSDBG_FATAL_FAILURE, + ("pidfile exists at %s\n", SSSD_PIDFILE_PATH)); + ERROR("SSSD is already running\n"); + return 2; + } + /* Parse config file, fail if cannot be done */ ret = load_configuration(tmp_ctx, config_file, &monitor); if (ret != EOK) { -- 1.7.11.4