Bug 613601 - buglet in dup_close_on_exec_fd()
authorRyan Lortie <desrt@desrt.ca>
Mon, 22 Mar 2010 16:59:08 +0000 (11:59 -0500)
committerRyan Lortie <desrt@desrt.ca>
Mon, 22 Mar 2010 17:03:24 +0000 (12:03 -0500)
Fix copy/paste error and 'or' FD_CLOEXEC into the existing flags instead
of just setting it outright.

gio/gunixfdlist.c

index df715b2..026c127 100644 (file)
@@ -117,10 +117,15 @@ dup_close_on_exec_fd (gint     fd,
     }
 
   do
-    s = fcntl (new_fd, F_SETFD, FD_CLOEXEC);
+    {
+      s = fcntl (new_fd, F_GETFD);
+
+      if (s >= 0)
+        s = fcntl (new_fd, F_SETFD, (long) (s | FD_CLOEXEC));
+    }
   while (s < 0 && (errno == EINTR));
 
-  if (new_fd < 0)
+  if (s < 0)
     {
       int saved_errno = errno;