vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Sat Mar 19 00:11:01 2011 +0200| [90ac674cb1d24f64cc8b38d5ea21be4dfeffb24a] | committer: Rémi Denis-Courmont
Use POSIX fcntl(F_DUPFD_CLOEXEC) instead of Linux dup3() As an added bonus, we don't need to open /dev/null for nothing. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=90ac674cb1d24f64cc8b38d5ea21be4dfeffb24a --- configure.ac | 2 +- src/posix/filesystem.c | 21 +++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 7de376d..07f859d 100644 --- a/configure.ac +++ b/configure.ac @@ -557,7 +557,7 @@ AC_CHECK_FUNCS(fdatasync,, AC_FUNC_STRCOLL dnl Check for non-standard system calls -AC_CHECK_FUNCS([accept4 dup3 pipe2 eventfd vmsplice sched_getaffinity]) +AC_CHECK_FUNCS([accept4 pipe2 eventfd vmsplice sched_getaffinity]) AH_BOTTOM([#include <vlc_fixups.h>]) diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c index 80576e1..9affc67 100644 --- a/src/posix/filesystem.c +++ b/src/posix/filesystem.c @@ -315,22 +315,15 @@ int vlc_dup (int oldfd) { int newfd; -#ifdef HAVE_DUP3 - /* Unfortunately, dup3() works like dup2(), not like plain dup(). So we - * need such contortion to find the new file descriptor while preserving - * thread safety of the file descriptor table. */ - newfd = vlc_open ("/dev/null", O_RDONLY); - if (likely(newfd != -1)) +#ifdef F_DUPFD_CLOEXEC + newfd = fcntl (oldfd, F_DUPFD_CLOEXEC); + if (unlikely(newfd == -1 || errno == EINVAL)) +#endif { - if (likely(dup3 (oldfd, newfd, O_CLOEXEC) == newfd)) - return newfd; - close (newfd); + newfd = dup (oldfd); + if (likely(newfd != -1)) + fcntl (newfd, F_SETFD, FD_CLOEXEC); } -#endif - - newfd = dup (oldfd); - if (likely(newfd != -1)) - fcntl (newfd, F_SETFD, FD_CLOEXEC); return newfd; } _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
