]> granicus.if.org Git - libevent/commitdiff
Avoid redundant syscall if making a socket cloexec twice
authorNick Mathewson <nickm@torproject.org>
Mon, 20 May 2013 16:30:40 +0000 (12:30 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 20 May 2013 16:30:40 +0000 (12:30 -0400)
I got the idea from Maxime's last patch.

evutil.c

index ce3ef31ce2f0542b8aef8827cf7627bcc31afcb4..60e6986b656ab51d5ffa634a0e6a054f0dbd1c46 100644 (file)
--- 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;