Avoid redundant syscall if making a socket cloexec twice

I got the idea from Maxime's last patch.
This commit is contained in:
Nick Mathewson 2013-05-20 12:30:40 -04:00
parent 42c03da9b9
commit 1f29b18f51

View File

@ -390,10 +390,12 @@ evutil_make_socket_closeonexec(evutil_socket_t fd)
event_warn("fcntl(%d, F_GETFD)", fd);
return -1;
}
if (!(flags & FD_CLOEXEC)) {
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
event_warn("fcntl(%d, F_SETFD)", fd);
return -1;
}
}
#endif
return 0;
}