diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-10-03 16:23:11 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-10-04 11:18:56 +0200 |
commit | e7dd2a5102ba6cfd28be6eccdd62768e9758d9f4 (patch) | |
tree | 4be1da8e238dc9f6cdacb88c4d3a9ee1ced6e64d /src/monitor | |
parent | e6e0d5a663a133b16938cea263557bf67d544e9c (diff) | |
download | sssd-e7dd2a5102ba6cfd28be6eccdd62768e9758d9f4.tar.gz sssd-e7dd2a5102ba6cfd28be6eccdd62768e9758d9f4.tar.xz sssd-e7dd2a5102ba6cfd28be6eccdd62768e9758d9f4.zip |
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.
Diffstat (limited to 'src/monitor')
-rw-r--r-- | src/monitor/monitor.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index fe46e172e..a9dd1ffda 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 @@ -1231,29 +1232,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; } @@ -2597,6 +2586,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) { |