diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-07-07 15:12:42 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-07-07 15:12:42 +0200 |
commit | 04a8f3ceedefa63f9344311e5ff05ab3ce754fda (patch) | |
tree | b95e680ff8e2ef267587f959ab0a7f6ae5d93227 /src/lib/shm_ap_rbuff.c | |
parent | 80441117cf61137c6a8c97e0779e70d76ae8541d (diff) | |
download | ouroboros-04a8f3ceedefa63f9344311e5ff05ab3ce754fda.tar.gz ouroboros-04a8f3ceedefa63f9344311e5ff05ab3ce754fda.zip |
lib: Add lockfile
The pid of the IRMd is stored in a lockfile in shared memory. This
makes checking if the IRMd is running independent of the
configuration, as previously the IRMd pid was stored at the end of the
shm_du_map, which could not be read by an IRMd that would be compiled
with different configuration options.
Also corrects some unnecessary includes
Fixes #21.
Diffstat (limited to 'src/lib/shm_ap_rbuff.c')
-rw-r--r-- | src/lib/shm_ap_rbuff.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index 4eb91136..cf795601 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -26,7 +26,7 @@ #include <ouroboros/logs.h> #include <ouroboros/shm_ap_rbuff.h> -#include <ouroboros/shm_du_map.h> +#include <ouroboros/lockfile.h> #include <pthread.h> #include <sys/mman.h> @@ -215,7 +215,7 @@ void shm_ap_rbuff_close(struct shm_ap_rbuff * rb) void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb) { char fn[25]; - struct shm_du_map * dum = NULL; + struct lockfile * lf = NULL; if (rb == NULL) { LOG_DBGF("Bogus input. Bugging out."); @@ -223,15 +223,17 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb) } if (rb->api != getpid()) { - dum = shm_du_map_open(); - if (shm_du_map_owner(dum) == getpid()) { + lf = lockfile_open(); + if (lf == NULL) + return; + if (lockfile_owner(lf) == getpid()) { LOG_DBGF("Ringbuffer %d destroyed by IRMd %d.", rb->api, getpid()); - shm_du_map_close(dum); + lockfile_close(lf); } else { LOG_ERR("AP-I %d tried to destroy rbuff owned by %d.", getpid(), rb->api); - shm_du_map_close(dum); + lockfile_close(lf); return; } } |