OSSP CVS Repository

ossp - Check-in [2987]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2987
Date: 2002-Dec-19 10:11:51 (local)
2002-Dec-19 09:11:51 (UTC)
User:rse
Branch:
Comment: Use "close-on-exec" semantic on internal file descriptors if underlying platform supports this feature. This makes sure the file descriptors are closed by the kernel upon execution of exec(3) by the application.

Hints by: Martin Kraemer <martin.kraemer@mch.sni.de>

Tickets:
Inspections:
Files:
ossp-pkg/mm/ChangeLog      1.37 -> 1.38     8 inserted, 2 deleted
ossp-pkg/mm/mm_core.c      1.16 -> 1.17     19 inserted, 0 deleted

ossp-pkg/mm/ChangeLog 1.37 -> 1.38

--- ChangeLog    2002/08/01 12:59:07     1.37
+++ ChangeLog    2002/12/19 09:11:51     1.38
@@ -13,12 +13,18 @@
     | |_ / __/ 
   __|_(_)_____|______________________________________________________
             
- Changes between 1.2.1 and 1.2.2 (28-Jul-2000 to xx-Aug-2002)
+ Changes between 1.2.1 and 1.2.2 (28-Jul-2002 to xx-Dec-2002)
+
+  *) Use "close-on-exec" semantic on internal file descriptors if
+     underlying platform supports this feature. This makes sure the file
+     descriptors are closed by the kernel upon execution of exec(3) by
+     the application.
+     [Ralf S. Engelschall, Martin Kraemer <martin.kraemer@mch.sni.de>]
 
   *) Fixed Makefile.in: $(TRUE) was not defined.
      [Will Day <wd@hpgx.net>]
 
- Changes between 1.2.0 and 1.2.1 (26-Jul-2000 to 28-Jul-2002)
+ Changes between 1.2.0 and 1.2.1 (26-Jul-2002 to 28-Jul-2002)
 
   *) Fixed the package rolling: configure.ac was missing because
      of a bug in devtool.conf.


ossp-pkg/mm/mm_core.c 1.16 -> 1.17

--- mm_core.c    2002/07/26 13:48:38     1.16
+++ mm_core.c    2002/12/19 09:11:51     1.17
@@ -130,6 +130,9 @@
     }
     if (fd == -1 && i < MM_MAXCHILD) {
         fd = open(mc->mc_fnsem, O_WRONLY, MM_CORE_FILEMODE);
+#if defined(F_SETFD) && defined(FD_CLOEXEC)
+        fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
         mc->mc_fdsem[i].pid = getpid();
         mc->mc_fdsem[i].fd  = fd;
     }
@@ -264,6 +267,10 @@
 #if defined(MM_SHMT_MMZERO)
     if ((fdmem = open("/dev/zero", O_RDWR, MM_CORE_FILEMODE)) == -1)
         FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to open /dev/zero");
+#if defined(F_SETFD) && defined(FD_CLOEXEC)
+    if (fcntl(fdmem, F_SETFD, FD_CLOEXEC) == -1)
+        FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to set close-on-exec flag");
+#endif
     if (lseek(fdmem, mm_core_mapoffset+size, SEEK_SET) == -1)
         FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to seek in /dev/zero");
     write(fdmem, &zero, sizeof(zero));
@@ -277,6 +284,10 @@
     unlink(fnmem);
     if ((fdmem = open(fnmem, O_RDWR|O_CREAT|O_EXCL, MM_CORE_FILEMODE)) == -1)
         FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to open memory file");
+#if defined(F_SETFD) && defined(FD_CLOEXEC)
+    if (fcntl(fdmem, F_SETFD, FD_CLOEXEC) == -1)
+        FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to set close-on-exec flag");
+#endif
     if (ftruncate(fdmem, mm_core_mapoffset+size) == -1)
         FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to truncate memory file");
     write(fdmem, &zero, sizeof(zero));
@@ -305,12 +316,20 @@
     unlink(fnsem);
     if ((fdsem = open(fnsem, O_RDWR|O_CREAT|O_EXCL, MM_CORE_FILEMODE)) == -1)
         FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to open semaphore file");
+#if defined(F_SETFD) && defined(FD_CLOEXEC)
+    if (fcntl(fdsem, F_SETFD, FD_CLOEXEC) == -1)
+        FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to set close-on-exec flag");
+#endif
 #endif /* MM_SEMT_FLOCK */
 
 #if defined(MM_SEMT_FCNTL)
     unlink(fnsem);
     if ((fdsem = open(fnsem, O_RDWR|O_CREAT|O_EXCL, MM_CORE_FILEMODE)) == -1)
         FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to open semaphore file");
+#if defined(F_SETFD) && defined(FD_CLOEXEC)
+    if (fcntl(fdsem, F_SETFD, FD_CLOEXEC) == -1)
+        FAIL(MM_ERR_CORE|MM_ERR_SYSTEM, "failed to set close-on-exec flag");
+#endif
 #endif /* MM_SEMT_FCNTL */
 
 #if defined(MM_SEMT_IPCSEM)

CVSTrac 2.0.1