summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-02-21 19:37:31 +0100
committerdimitri staessens <dimitri.staessens@ugent.be>2017-02-21 19:37:31 +0100
commitffe3262f5e78d67aa6b4214f0533ed8ada913442 (patch)
treec16a4a1c829862363cd826a5a256b993b18de2bc /src/irmd
parent2a73f2d58cd29c6ecaade828db6ce1f5dde18a0e (diff)
downloadouroboros-ffe3262f5e78d67aa6b4214f0533ed8ada913442.tar.gz
ouroboros-ffe3262f5e78d67aa6b4214f0533ed8ada913442.zip
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.
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c44
1 files changed, 22 insertions, 22 deletions
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;