Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix: make uv__cloexec() EINTR resilient

It's somewhat underspecified if and when fcntl() can return EINTR. It never
does on Linux for F_GETFD or F_SETFD but let's not make any assumptions.
  • Loading branch information...
bnoordhuis authored and piscisaureus committed Jun 13, 2012
1 parent 07c6ac2 commit b3a97f89812b19b67a35906ad4ca7eb850be28f0
Showing with 20 additions and 14 deletions.
  1. +20 −14 src/unix/core.c
@@ -487,30 +487,36 @@ int uv__nonblock(int fd, int set) {


int uv__cloexec(int fd, int set) {
int flags;
int r;

#if __linux__
/* Linux knows only FD_CLOEXEC so we can safely omit the fcntl(F_GETFD)
* syscall. CHECKME: That's probably true for other Unices as well.
*/
return fcntl(fd, F_SETFD, set ? FD_CLOEXEC : 0);
if (set)
flags = FD_CLOEXEC;
else
flags = 0;
#else
int flags;
do
r = fcntl(fd, F_GETFD);
while (r == -1 && errno == EINTR);

if ((flags = fcntl(fd, F_GETFD)) == -1) {
if (r == -1)
return -1;
}

if (set) {
flags |= FD_CLOEXEC;
} else {
flags &= ~FD_CLOEXEC;
}
if (set)
flags = r | FD_CLOEXEC;
else
flags = r & ~FD_CLOEXEC;
#endif

if (fcntl(fd, F_SETFD, flags) == -1) {
return -1;
}
do
r = fcntl(fd, F_SETFD, flags);
while (r == -1 && errno == EINTR);

return 0;
#endif
return r;
}


0 comments on commit b3a97f8

Please sign in to comment.
You can’t perform that action at this time.