]> git.sesse.net Git - vlc/commitdiff
utf8_open: set the close-on-exec descriptor flag
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 27 Jan 2009 15:55:34 +0000 (17:55 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 27 Jan 2009 16:06:28 +0000 (18:06 +0200)
This departs from utf8_open() being a pure open() + Unicode function.
We should really always set the flag anyway, so lets factor the code.
There is still a tiny race between open() and the second fcntl() system
call, but it cannot quite be fixed within the current POSIX standards.

By the way, the correct way to clear the flag would be _after_ fork(),
but I am not aware of any such case involving utf8_open() in the
current tree.

src/text/filesystem.c

index 227ed0bbe44c02c83fb657737aced7665d109b82..5670d8459d8b20626383f1f08eff1f303cba19fc 100644 (file)
@@ -111,6 +111,13 @@ int utf8_open (const char *filename, int flags, mode_t mode)
     }
 
     int 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;
 }