[FFmpeg-cvslog] avutil/file_open: avoid file handle inheritance on Windows

Tobias Rapp git at videolan.org
Sun Dec 6 12:57:14 CET 2015


ffmpeg | branch: release/2.4 | Tobias Rapp <t.rapp at noa-audio.com> | Thu Oct 29 09:11:37 2015 +0100| [1bb7529ac2eda7d3b7ffffeb20ec477d4440b944] | committer: Michael Niedermayer

avutil/file_open: avoid file handle inheritance on Windows

Avoids inheritance of file handles on Windows systems similar to the
O_CLOEXEC/FD_CLOEXEC flag on Linux.

Fixes file lock issues in Windows applications when a child process
is started with handle inheritance enabled (standard input/output
redirection) while a FFmpeg transcoding is running in the parent
process.

Links relevant to the subject:

https://msdn.microsoft.com/en-us/library/w7sa2b22.aspx

Describes the _wsopen() function and the O_NOINHERIT flag. File handles
opened by _wsopen() are inheritable by default.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx

Describes handle inheritance when creating new processes. Handle
inheritance must be enabled (bInheritHandles = TRUE) e.g. when you want
to pass handles for stdin/stdout via lpStartupInfo.

Signed-off-by: Tobias Rapp <t.rapp at noa-audio.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 474665346616e446ecd1407002fdf5f88201bf72)

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1bb7529ac2eda7d3b7ffffeb20ec477d4440b944
---

 libavutil/file_open.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavutil/file_open.c b/libavutil/file_open.c
index f3164eb..619dc57 100644
--- a/libavutil/file_open.c
+++ b/libavutil/file_open.c
@@ -82,6 +82,9 @@ int avpriv_open(const char *filename, int flags, ...)
 #ifdef O_CLOEXEC
     flags |= O_CLOEXEC;
 #endif
+#ifdef O_NOINHERIT
+    flags |= O_NOINHERIT;
+#endif
 
     fd = open(filename, flags, mode);
 #if HAVE_FCNTL



More information about the ffmpeg-cvslog mailing list