diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-07-07 15:44:16 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-07-07 15:44:16 +0200 |
commit | cc377e56c6fd25403fc7ccf5f83c82e3d85a767b (patch) | |
tree | 33604c48880d3a01d7053608584236dd15fc43e8 /src/irmd | |
parent | 80441117cf61137c6a8c97e0779e70d76ae8541d (diff) | |
parent | b3870ef695a256be4a4ed28a991c39aab37bd6f3 (diff) | |
download | ouroboros-cc377e56c6fd25403fc7ccf5f83c82e3d85a767b.tar.gz ouroboros-cc377e56c6fd25403fc7ccf5f83c82e3d85a767b.zip |
Merged in dstaesse/ouroboros/be-lockfile (pull request #165)
lib: Add lockfile
Diffstat (limited to 'src/irmd')
-rw-r--r-- | src/irmd/main.c | 34 | ||||
-rw-r--r-- | src/irmd/registry.c | 2 |
2 files changed, 23 insertions, 13 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index 1f72fa1a..19bc5b9b 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -24,6 +24,7 @@ #define OUROBOROS_PREFIX "irmd" #include <ouroboros/config.h> +#include <ouroboros/errno.h> #include <ouroboros/logs.h> #include <ouroboros/sockets.h> #include <ouroboros/ipcp.h> @@ -31,6 +32,7 @@ #include <ouroboros/list.h> #include <ouroboros/utils.h> #include <ouroboros/irm_config.h> +#include <ouroboros/lockfile.h> #include <ouroboros/shm_ap_rbuff.h> #include <ouroboros/shm_du_map.h> #include <ouroboros/bitmap.h> @@ -45,7 +47,6 @@ #include <sys/un.h> #include <signal.h> #include <stdlib.h> -#include <errno.h> #include <string.h> #include <limits.h> #include <pthread.h> @@ -106,6 +107,7 @@ struct irm { pthread_rwlock_t flows_lock; enum irm_state state; + struct lockfile * lf; struct shm_du_map * dum; pthread_t * threadpool; int sockfd; @@ -1331,6 +1333,9 @@ static void irm_destroy() if (instance->dum != NULL) shm_du_map_destroy(instance->dum); + if (instance->lf != NULL) + lockfile_destroy(instance->lf); + close(instance->sockfd); pthread_rwlock_unlock(&instance->state_lock); @@ -1698,28 +1703,28 @@ static struct irm * irm_create() instance->state = IRMD_NULL; - if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { - struct shm_du_map * dum = shm_du_map_open(); - - if (dum == NULL) { - LOG_ERR("Could not examine existing shm file."); + if (access("/dev/shm/" LOCKFILE_NAME, F_OK) != -1) { + struct lockfile * lf = lockfile_open(); + if (lf == NULL) { + LOG_ERR("Failed to open existing lockfile."); free(instance); return NULL; } - if (kill(shm_du_map_owner(dum), 0) < 0) { + if (kill(lockfile_owner(lf), 0) < 0) { LOG_INFO("IRMd didn't properly shut down last time."); - shm_du_map_destroy(dum); - LOG_INFO("Stale shm file removed."); + shm_du_map_destroy(shm_du_map_open()); + LOG_INFO("Stale resources cleaned"); + lockfile_destroy(lf); } else { LOG_INFO("IRMd already running (%d), exiting.", - shm_du_map_owner(dum)); - shm_du_map_close(dum); + lockfile_owner(lf)); + lockfile_close(lf); free(instance); return NULL; } - shm_du_map_close(dum); + lockfile_close(lf); } if (pthread_rwlock_init(&instance->state_lock, NULL)) { @@ -1777,6 +1782,11 @@ static struct irm * irm_create() return NULL; } + if ((instance->lf = lockfile_create()) == NULL) { + irm_destroy(); + return NULL; + } + if ((instance->dum = shm_du_map_create()) == NULL) { irm_destroy(); return NULL; diff --git a/src/irmd/registry.c b/src/irmd/registry.c index ae532d5a..c5f81d77 100644 --- a/src/irmd/registry.c +++ b/src/irmd/registry.c @@ -26,13 +26,13 @@ #define OUROBOROS_PREFIX "registry" +#include <ouroboros/errno.h> #include <ouroboros/logs.h> #include <ouroboros/irm_config.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> -#include <errno.h> struct reg_instance * reg_instance_create(pid_t api) { |