unix: don't retry dup2/dup3 on EINTR

Like the previous commit, but this time for UNIX platforms other than
Linux.

As far as I have been able to establish, dup2 and dup3 never return
EINTR on OS X and FreeBSD.  Even if other platforms do return EINTR,
it's probably still better not to retry because it's unspecified
whether the file descriptor has been closed.

Fixes: https://github.com/libuv/libuv/issues/462
PR-URL: https://github.com/libuv/libuv/pull/608
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2015-11-05 17:06:53 +01:00
parent af7a3614d0
commit 9bbc1137ee

View File

@ -960,16 +960,12 @@ int uv__open_cloexec(const char* path, int flags) {
int uv__dup2_cloexec(int oldfd, int newfd) {
int r;
#if defined(__FreeBSD__) && __FreeBSD__ >= 10
do
r = dup3(oldfd, newfd, O_CLOEXEC);
while (r == -1 && errno == EINTR);
r = dup3(oldfd, newfd, O_CLOEXEC);
if (r == -1)
return -errno;
return r;
#elif defined(__FreeBSD__) && defined(F_DUP2FD_CLOEXEC)
do
r = fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd);
while (r == -1 && errno == EINTR);
r = fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd);
if (r != -1)
return r;
if (errno != EINVAL)
@ -996,7 +992,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
#if defined(__linux__)
while (r == -1 && errno == EBUSY);
#else
while (r == -1 && errno == EINTR);
while (0); /* Never retry. */
#endif
if (r == -1)