]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - linux/src/api/gates/GateHWSpinlock.c
Add FD_CLOEXEC flag for sockets, /dev/mem and LAD pipes
[ipc/ipcdev.git] / linux / src / api / gates / GateHWSpinlock.c
index 3ec7e136592de064ab7b671fc2c7df107d01e234..b57016a99cfd2aa4ec83f2d220b4248e1885af9d 100644 (file)
@@ -171,6 +171,7 @@ Int32 GateHWSpinlock_start(Void)
     Int32               status = GateHWSpinlock_S_SUCCESS;
     UInt32              dst;
     Int32               fdMem;
+    int                 flags;
 
     fdMem = open ("/dev/mem", O_RDWR | O_SYNC);
 
@@ -179,6 +180,12 @@ Int32 GateHWSpinlock_start(Void)
         status = GateHWSpinlock_E_OSFAILURE;
     }
 
+    /* make sure /dev/mem fd doesn't exist for 'fork() -> exec*()'ed child */
+    flags = fcntl(fdMem, F_GETFD);
+    if (flags != -1) {
+        fcntl(fdMem, F_SETFD, flags | FD_CLOEXEC);
+    }
+
     /* map the hardware lock registers into the local address space */
     if (status == GateHWSpinlock_S_SUCCESS) {
         dst = (UInt32)mmap(NULL, _GateHWSpinlock_cfgParams.size,