diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-06-17 15:55:23 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-06-17 16:01:20 +0200 |
commit | dba896b9a0ca7cbe4fb379017672bd44a0a77ef0 (patch) | |
tree | 5aeee1a6f05aa4a35ceab97ba6a7da16979555a5 /src/irmd/main.c | |
parent | 1d196cfc0d87b6fd41ba15a3a7d17669711ed202 (diff) | |
download | ouroboros-dba896b9a0ca7cbe4fb379017672bd44a0a77ef0.tar.gz ouroboros-dba896b9a0ca7cbe4fb379017672bd44a0a77ef0.zip |
irmd, lib: use shm_du_map as lockfile.
Added the pid of the irmd to the shm_du_map. The IRMd will check for
an existing shm_du_map. If there is an existing file, it will exit if
the owner IRMd is running or remove it if the owner IRMd is not
running.
Also simplifies calculation of the shm_du_map pointers and corrects
exiting calls for the IRMd.
Fixes #8.
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index c20d63db..87625205 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1555,11 +1555,20 @@ static struct irm * irm_create() return NULL; if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { - LOG_ERR("IRM daemon is running in this system."); - LOG_ERR("If you think this message is in error,"); - LOG_ERR("please remove /dev/shm/" SHM_DU_MAP_FILENAME); - LOG_ERR("(root privileges required) or reboot your system."); - return NULL; + struct shm_du_map * dum = shm_du_map_open(); + if (dum == NULL) { + LOG_ERR("Could not examine existing shm file."); + exit(EXIT_FAILURE); + } + if (kill(shm_du_map_owner(dum), 0) < 0) { + LOG_INFO("IRMd didn't properly shut down last time."); + shm_du_map_destroy(dum); + LOG_INFO("Stale shm file removed."); + } else { + LOG_WARN("IRMd already running, exiting."); + free(i); + exit(EXIT_SUCCESS); + } } i->threadpool = malloc(sizeof(pthread_t) * IRMD_THREADPOOL_SIZE); @@ -1621,19 +1630,18 @@ int main() sig_act.sa_flags = SA_SIGINFO; if (sigaction(SIGINT, &sig_act, NULL) < 0) - exit(1); + exit(EXIT_FAILURE); if (sigaction(SIGTERM, &sig_act, NULL) < 0) - exit(1); + exit(EXIT_FAILURE); if (sigaction(SIGHUP, &sig_act, NULL) < 0) - exit(1); + exit(EXIT_FAILURE); if (sigaction(SIGPIPE, &sig_act, NULL) < 0) - exit(1); + exit(EXIT_FAILURE); instance = irm_create(); if (instance == NULL) return 1; - pthread_create(&instance->cleanup_flows, NULL, irm_flow_cleaner, NULL); for (t = 0; t < IRMD_THREADPOOL_SIZE; ++t) @@ -1647,5 +1655,5 @@ int main() irm_destroy(instance); - return 0; + exit(EXIT_SUCCESS); } |