Commit a1e644f7 authored by Rémi Denis-Courmont's avatar 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.
parent 8f6ca154
......@@ -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>])
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment