summaryrefslogtreecommitdiff
path: root/src/lib/shm_du_map.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-06 19:21:11 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-06 19:21:11 +0200
commitff09baf0cf9ec501ec54d2666e386238bc7e6389 (patch)
tree0966469900595c3f51acac2d9bb89429a826f1b0 /src/lib/shm_du_map.c
parent4fb0d2bfb7486936ef05721667f03eccf664d56e (diff)
parentdbed235ff41b9ae72b188e57888bacc984a43d75 (diff)
downloadouroboros-ff09baf0cf9ec501ec54d2666e386238bc7e6389.tar.gz
ouroboros-ff09baf0cf9ec501ec54d2666e386238bc7e6389.zip
Merged in dstaesse/ouroboros/be-clean-exit (pull request #160)
lib: shm_du_map: Clean sdus upon exit
Diffstat (limited to 'src/lib/shm_du_map.c')
-rw-r--r--src/lib/shm_du_map.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c
index 6289857f..68452158 100644
--- a/src/lib/shm_du_map.c
+++ b/src/lib/shm_du_map.c
@@ -123,8 +123,10 @@ static void clean_sdus(struct shm_du_map * dum, pid_t api)
if (kill(api, 0) == 0) {
struct shm_ap_rbuff * rb;
rb = shm_ap_rbuff_open(api);
- shm_ap_rbuff_reset(rb);
- shm_ap_rbuff_close(rb);
+ if (rb != NULL) {
+ shm_ap_rbuff_reset(rb);
+ shm_ap_rbuff_close(rb);
+ }
}
*dum->choked = 0;
@@ -347,6 +349,24 @@ void * shm_du_map_sanitize(void * o)
return (void *) 0;
}
+void shm_du_map_close_on_exit(struct shm_du_map * dum)
+{
+ if (dum == NULL) {
+ LOG_DBGF("Bogus input. Bugging out.");
+ return;
+ }
+
+ clean_sdus(dum, getpid());
+
+ if (close(dum->fd) < 0)
+ LOG_DBGF("Couldn't close shared memory.");
+
+ if (munmap(dum->shm_base, SHM_FILE_SIZE) == -1)
+ LOG_DBGF("Couldn't unmap shared memory.");
+
+ free(dum);
+}
+
void shm_du_map_close(struct shm_du_map * dum)
{
if (dum == NULL) {
@@ -370,6 +390,11 @@ void shm_du_map_destroy(struct shm_du_map * dum)
return;
}
+ if (getpid() != *dum->api) {
+ LOG_DBGF("Only IRMd can destroy %s.", SHM_DU_MAP_FILENAME);
+ return;
+ }
+
if (close(dum->fd) < 0)
LOG_DBGF("Couldn't close shared memory.");