[vlc-devel] commit: Linux: (try to) set close-on-exec in open() system call ( 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 18:04:11 2009 +0200| [825731a114f4614f3d3ac6f4d389e15205a302de] | committer: Rémi Denis-Courmont
Linux: (try to) set close-on-exec in open() system call
This Linux-specific extension fixes the close-on-exec race.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=825731a114f4614f3d3ac6f4d389e15205a302de
---
src/text/filesystem.c | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 5670d84..13f86bf 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -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;
}
More information about the vlc-devel
mailing list