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,, ...@@ -557,7 +557,7 @@ AC_CHECK_FUNCS(fdatasync,,
AC_FUNC_STRCOLL AC_FUNC_STRCOLL
dnl Check for non-standard system calls 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>]) AH_BOTTOM([#include <vlc_fixups.h>])
......
...@@ -315,22 +315,15 @@ int vlc_dup (int oldfd) ...@@ -315,22 +315,15 @@ int vlc_dup (int oldfd)
{ {
int newfd; int newfd;
#ifdef HAVE_DUP3 #ifdef F_DUPFD_CLOEXEC
/* Unfortunately, dup3() works like dup2(), not like plain dup(). So we newfd = fcntl (oldfd, F_DUPFD_CLOEXEC);
* need such contortion to find the new file descriptor while preserving if (unlikely(newfd == -1 && errno == EINVAL))
* thread safety of the file descriptor table. */
newfd = vlc_open ("/dev/null", O_RDONLY);
if (likely(newfd != -1))
{
if (likely(dup3 (oldfd, newfd, O_CLOEXEC) == newfd))
return newfd;
close (newfd);
}
#endif #endif
{
newfd = dup (oldfd); newfd = dup (oldfd);
if (likely(newfd != -1)) if (likely(newfd != -1))
fcntl (newfd, F_SETFD, FD_CLOEXEC); fcntl (newfd, F_SETFD, FD_CLOEXEC);
}
return newfd; 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