[vlc-devel] commit: Set close-on-exec file for file inputs ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Oct 12 13:13:17 CEST 2008


vlc | branch: 0.9-bugfix | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Oct 11 20:11:08 2008 +0300| [dc92656d4c5d371fc71b3ba1085807024d7e65bc] | committer: Rémi Denis-Courmont 

Set close-on-exec file for file inputs

We don't want to leak descriptors to child PROCESSES (!= threads) such
as the pseudo-CGI interface. The socket wrappers ahve already been doing
that for a while. Unfortunately, there are still many "leaks", through
underlying libraries, opendir(), fopen(), etc. And then, this is not
thread-safe (we leak if another thread calls fork() between open() and
fcntl()). This is a well-known limitation in POSIX anyway.
(cherry picked from commit 90ba04f49ebbaccf9efafe93b3975bf18a236418)

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

 modules/access/file.c |    1 +
 modules/access/mmap.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/modules/access/file.c b/modules/access/file.c
index 1151c4d..f2154b3 100644
--- a/modules/access/file.c
+++ b/modules/access/file.c
@@ -380,6 +380,7 @@ static int open_file (access_t *p_access, const char *path)
                         _("VLC could not open the file \"%s\"."), path);
         return -1;
     }
+    fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC);
 
 # if defined(HAVE_FCNTL_H)
     /* We'd rather use any available memory for reading ahead
diff --git a/modules/access/mmap.c b/modules/access/mmap.c
index 0310e42..07adfbc 100644
--- a/modules/access/mmap.c
+++ b/modules/access/mmap.c
@@ -104,6 +104,7 @@ static int Open (vlc_object_t *p_this)
         msg_Warn (p_access, "cannot open %s: %m", path);
         goto error;
     }
+    fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC);
 
     /* mmap() is only safe for regular and block special files.
      * For other types, it may be some idiosyncrasic interface (e.g. packet




More information about the vlc-devel mailing list