From ffe3262f5e78d67aa6b4214f0533ed8ada913442 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 21 Feb 2017 19:37:31 +0100 Subject: irmd: Fix detection of IRMd When starting two IRMds, the second one exits, but applications can't contact the first because the second instance took the UNIX socket. Now the lockfile is checked for running IRMd instances before opening the UNIX socket. --- src/irmd/main.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index 7f20faf4..e1071920 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -2048,6 +2048,28 @@ static int irm_create(void) return -ENOMEM; } + if ((irmd->lf = lockfile_create()) == NULL) { + if ((irmd->lf = lockfile_open()) == NULL) { + log_err("Lockfile error."); + irm_destroy(); + return -1; + } + + if (kill(lockfile_owner(irmd->lf), 0) < 0) { + log_info("IRMd didn't properly shut down last time."); + shm_rdrbuff_destroy(shm_rdrbuff_open()); + log_info("Stale resources cleaned."); + lockfile_destroy(irmd->lf); + irmd->lf = lockfile_create(); + } else { + log_info("IRMd already running (%d), exiting.", + lockfile_owner(irmd->lf)); + lockfile_close(irmd->lf); + free(irmd); + return -1; + } + } + if (stat(SOCK_PATH, &st) == -1) { if (mkdir(SOCK_PATH, 0777)) { log_err("Failed to create sockets directory."); @@ -2075,28 +2097,6 @@ static int irm_create(void) return -1; } - if ((irmd->lf = lockfile_create()) == NULL) { - if ((irmd->lf = lockfile_open()) == NULL) { - log_err("Lockfile error."); - irm_destroy(); - return -1; - } - - if (kill(lockfile_owner(irmd->lf), 0) < 0) { - log_info("IRMd didn't properly shut down last time."); - shm_rdrbuff_destroy(shm_rdrbuff_open()); - log_info("Stale resources cleaned."); - lockfile_destroy(irmd->lf); - irmd->lf = lockfile_create(); - } else { - log_info("IRMd already running (%d), exiting.", - lockfile_owner(irmd->lf)); - lockfile_close(irmd->lf); - free(irmd); - return -1; - } - } - if (irmd->lf == NULL) { irm_destroy(); return -1; -- cgit v1.2.3