[PATCH] lib: Fix bad unlinking of old shared memory

  • From: Sander Vrijders <sander.vrijders@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Wed, 25 Apr 2018 15:46:43 +0200

A previous commit tried to stat the shared memory file in case it was
already there, but stat does not seem to work for shared memory
files. This simply omits the O_EXCL attribute upon creation of the
shared memory file, since pids are unique anyway.

Signed-off-by: Sander Vrijders <sander.vrijders@xxxxxxxx>
---
 src/lib/shm_flow_set.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c
index ca3a1a8..d2107fc 100644
--- a/src/lib/shm_flow_set.c
+++ b/src/lib/shm_flow_set.c
@@ -84,20 +84,16 @@ struct shm_flow_set * shm_flow_set_create()
         mode_t                mask;
         int                   shm_fd;
         int                   i;
-        struct stat           st;
 
         sprintf(fn, SHM_FLOW_SET_PREFIX "%d", getpid());
 
-        if (stat(fn, &st) != -1 && unlink(fn))
-                return NULL;
-
         set = malloc(sizeof(*set));
         if (set == NULL)
                 return NULL;
 
         mask = umask(0);
 
-        shm_fd = shm_open(fn, O_CREAT | O_EXCL | O_RDWR, 0666);
+        shm_fd = shm_open(fn, O_CREAT | O_RDWR, 0666);
         if (shm_fd == -1) {
                 free(set);
                 return NULL;
-- 
2.17.0


Other related posts: