summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-04-12 06:08:31 +0000
committerUlrich Drepper <drepper@redhat.com>2000-04-12 06:08:31 +0000
commitfb125e0ced340f0f0126cdcd3a230188007ef3f4 (patch)
tree6ed5cb0dd3c9ab842f9edc21c1c7040e6f10e3e0
parenta63be9f77713b1024335c053dafd58a6cd7075bb (diff)
downloadglibc-fb125e0ced340f0f0126cdcd3a230188007ef3f4.tar.gz
glibc-fb125e0ced340f0f0126cdcd3a230188007ef3f4.tar.xz
glibc-fb125e0ced340f0f0126cdcd3a230188007ef3f4.zip
Update.
	* sysdeps/unix/sysv/linux/shm_open.c (shm_open): Set FD_CLOEXEC
	for descriptor.
-rw-r--r--ChangeLog3
-rw-r--r--sysdeps/unix/sysv/linux/shm_open.c25
2 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index fcecf3613f..61e7fd5b58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2000-04-11  Ulrich Drepper  <drepper@redhat.com>
 
+	* sysdeps/unix/sysv/linux/shm_open.c (shm_open): Set FD_CLOEXEC
+	for descriptor.
+
 	* misc/sys/mman.h: Add prototypes for shm_open and shm_unlink.
 	* rt/Makefile (librt-routines): Add shm_open and shm_unlink.
 	* rt/Versions [librt] (GLIBC_2.2): Add shm_open and shm_unlink.
diff --git a/sysdeps/unix/sysv/linux/shm_open.c b/sysdeps/unix/sysv/linux/shm_open.c
index 08bdaeadbd..ca24424b78 100644
--- a/sysdeps/unix/sysv/linux/shm_open.c
+++ b/sysdeps/unix/sysv/linux/shm_open.c
@@ -121,6 +121,7 @@ shm_open (const char *name, int oflag, mode_t mode)
 {
   size_t namelen;
   char *fname;
+  int fd;
 
   /* Determine where the shmfs is mounted.  */
   __libc_once (once, where_is_shmfs);
@@ -153,7 +154,29 @@ shm_open (const char *name, int oflag, mode_t mode)
      file on the shmfs.  If this is what should be done the whole function
      should be revamped since we can determine whether shmfs is available
      while trying to open the file, all in one turn.  */
-  return open (fname, oflag, mode);
+  fd = open (fname, oflag, mode);
+  if (fd != -1)
+    {
+      /* We got a descriptor.  Now set the FD_CLOEXEC bit.  */
+      int flags = fcntl (fd, F_GETFD, 0);
+
+      if (__builtin_expect (flags, 0) >= 0)
+	{
+	  flags |= FD_CLOEXEC;
+	  flags = fcntl (fd, F_SETFD, flags);
+	}
+
+      if (flags == -1)
+	{
+	  /* Something went wrong.  We cannot return the descriptor.  */
+	  int save_errno = errno;
+	  close (fd);
+	  fd = -1;
+	  __set_errno (save_errno);
+	}
+    }
+
+  return fd;
 }