[SSSD] [PATCH] Check for existing pidfile before starting the providers

Jakub Hrozek jhrozek at redhat.com
Wed Oct 3 14:29:22 UTC 2012


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.
-------------- next part --------------
>From e84f375c19c542dbad2f9efe4cc6c22ef9524865 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
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 | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 920d01c0d1bbf9153d80ebf7bfab9387646e4ec6..e8c987c3cfa0f12bd1b2c286cd17ddb7a15b7112 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;
     }
 
-    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



More information about the sssd-devel mailing list