diff --git a/evutil.c b/evutil.c index ce3ef31c..60e6986b 100644 --- a/evutil.c +++ b/evutil.c @@ -390,9 +390,11 @@ evutil_make_socket_closeonexec(evutil_socket_t fd) event_warn("fcntl(%d, F_GETFD)", fd); return -1; } - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) { - event_warn("fcntl(%d, F_SETFD)", 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;