]> git.sesse.net Git - vlc/commitdiff
Linux: (try to) set close-on-exec in open() system call
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 27 Jan 2009 16:04:11 +0000 (18:04 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 27 Jan 2009 16:12:31 +0000 (18:12 +0200)
This Linux-specific extension fixes the close-on-exec race.

src/text/filesystem.c

index 5670d8459d8b20626383f1f08eff1f303cba19fc..13f86bf44aa20dc6be24eb894eeb291dde7eb6f9 100644 (file)
@@ -110,14 +110,23 @@ int utf8_open (const char *filename, int flags, mode_t mode)
         return -1;
     }
 
-    int fd = open (local_name, flags, mode);
-#ifdef HAVE_FCNTL
-    if (fd != -1)
+    int fd;
+
+#ifdef O_CLOEXEC
+    fd = open (local_name, flags | O_CLOEXEC, mode);
+    if (fd == -1 && errno == EINVAL)
+#endif
     {
-        int flags = fcntl (fd, F_GETFD);
-        fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
-    }
+        fd = open (local_name, flags, mode);
+#ifdef HAVE_FCNTL
+        if (fd != -1)
+        {
+            int flags = fcntl (fd, F_GETFD);
+            fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
+        }
 #endif
+    }
+
     LocaleFree (local_name);
     return fd;
 }