[PATCH] Use O_CLOEXEC for internal file descriptors

Adam Jackson ajax at redhat.com
Mon Feb 27 13:45:47 PST 2012


On Mon, 2012-02-27 at 22:22 +0100, Mark Kettenis wrote:

> That is of course a much better suggestion.  And it is possible to use
> the same trick with gzdopen(3) to work around the fact that gzopen()
> doesn't suppert "e", even on Linux systems.

diff -up zlib-1.2.5/gzlib.c.jx zlib-1.2.5/gzlib.c
--- zlib-1.2.5/gzlib.c.jx	2010-04-18 13:53:22.000000000 -0400
+++ zlib-1.2.5/gzlib.c	2012-02-27 16:43:13.991022599 -0500
@@ -90,6 +90,7 @@ local gzFile gz_open(path, fd, mode)
     const char *mode;
 {
     gz_statep state;
+    int want_cloexec = 0;
 
     /* allocate gzFile structure to return */
     state = malloc(sizeof(gz_state));
@@ -122,6 +123,9 @@ local gzFile gz_open(path, fd, mode)
             case '+':       /* can't read and write at the same time */
                 free(state);
                 return NULL;
+	     case 'e':
+		 want_cloexec = 1;
+		 break;
             case 'b':       /* ignore -- will request binary anyway */
                 break;
             case 'f':
@@ -164,6 +168,9 @@ local gzFile gz_open(path, fd, mode)
 #ifdef O_BINARY
             O_BINARY |
 #endif
+#ifdef O_CLOEXEC
+	     (want_cloexec ? O_CLOEXEC : 0) |
+#endif
             (state->mode == GZ_READ ?
                 O_RDONLY :
                 (O_WRONLY | O_CREAT | (
---

There, fixed that for you.

- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.x.org/archives/xorg-devel/attachments/20120227/37477c03/attachment.pgp>


More information about the xorg-devel mailing list