From 1f29b18f51cb7080c1ffe5f51557979b71451b6a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 20 May 2013 12:30:40 -0400 Subject: Avoid redundant syscall if making a socket cloexec twice I got the idea from Maxime's last patch. --- evutil.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'evutil.c') 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; -- cgit v1.2.1