From: Michael Niedermayer <[email protected]> If we can make use of O_CLOEXEC, we don't need the fcntl() call. On systems that don't support O_CLOEXEC, try to reconfigure the file descriptor using the fcntl() API, but ignore failures.
Fixes CID1087079 Signed-off-by: Reinhard Tartler <[email protected]> --- libavutil/file_open.c | 8 +++++--- libavutil/internal.h | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libavutil/file_open.c b/libavutil/file_open.c index 765eb60..42ecafd 100644 --- a/libavutil/file_open.c +++ b/libavutil/file_open.c @@ -19,6 +19,7 @@ #include "config.h" #include "internal.h" #include "mem.h" +#include "log.h" #include <stdarg.h> #include <fcntl.h> #include <sys/stat.h> @@ -84,9 +85,10 @@ int avpriv_open(const char *filename, int flags, ...) #endif fd = open(filename, flags, mode); -#if HAVE_FCNTL - if (fd != -1) - fcntl(fd, F_SETFD, FD_CLOEXEC); + +#if !defined O_CLOEXEC && defined FD_CLOEXEC && defined HAVE_FCNTL + /* This is a weird case, cf. https://patches.libav.org/patch/54004/ */ + (void)fcntl(fd, F_SETFD, FD_CLOEXEC); #endif return fd; diff --git a/libavutil/internal.h b/libavutil/internal.h index aed9925..1d27196 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -217,6 +217,11 @@ void avpriv_request_sample(void *avc, /** * A wrapper for open() setting O_CLOEXEC. + * + * On systems that do not support O_CLOEXEC, this wrapper tries to + * reconfigure the file descriptor using fcntl, if that API is + * available. Possible errors of this reconfiguration are not being + * propagated. */ int avpriv_open(const char *filename, int flags, ...); -- 2.1.0 _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
