From: Miroslav Lichvar Date: Thu, 8 Aug 2019 15:32:23 +0000 (+0200) Subject: util: add debug messages to UTI_FdSetCloexec() X-Git-Tag: 4.0-pre1~155 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=622769cdfd458e81c3542e639a26a40d973cf35f;p=thirdparty%2Fchrony.git util: add debug messages to UTI_FdSetCloexec() --- diff --git a/socket.c b/socket.c index e285a5fe..77d34998 100644 --- a/socket.c +++ b/socket.c @@ -187,7 +187,6 @@ open_socket(int domain, int type, int flags) (socket_flags & SOCK_CLOEXEC) == 0 && #endif !UTI_FdSetCloexec(sock_fd)) { - DEBUG_LOG("Could not set O_CLOEXEC : %s", strerror(errno)); close(sock_fd); return INVALID_SOCK_FD; } diff --git a/util.c b/util.c index e8bdea29..5dd1b114 100644 --- a/util.c +++ b/util.c @@ -888,12 +888,19 @@ UTI_FdSetCloexec(int fd) int flags; flags = fcntl(fd, F_GETFD); - if (flags != -1) { - flags |= FD_CLOEXEC; - return !fcntl(fd, F_SETFD, flags); + if (flags == -1) { + DEBUG_LOG("fcntl() failed : %s", strerror(errno)); + return 0; } - return 0; + flags |= FD_CLOEXEC; + + if (fcntl(fd, F_SETFD, flags) < 0) { + DEBUG_LOG("fcntl() failed : %s", strerror(errno)); + return 0; + } + + return 1; } /* ================================================== */