[vlc-devel] commit: utf8_open: set the close-on-exec descriptor flag ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue Jan 27 17:14:04 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Tue Jan 27 17:55:34 2009 +0200| [9f59c6743b8aec7598f2f6145fc417c469a7c9a1] | committer: Rémi Denis-Courmont 

utf8_open: set the close-on-exec descriptor flag

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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9f59c6743b8aec7598f2f6145fc417c469a7c9a1
---

 src/text/filesystem.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 227ed0b..5670d84 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -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;
 }




More information about the vlc-devel mailing list