]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: add debug messages to UTI_FdSetCloexec()
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 8 Aug 2019 15:32:23 +0000 (17:32 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 8 Aug 2019 15:32:48 +0000 (17:32 +0200)
socket.c
util.c

index e285a5fed16e35dd8879c977622c4974ffc8109a..77d34998ae47a06e3ac2dfaf291b187ca3800e38 100644 (file)
--- 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 e8bdea297bc9853e5f79ec2c6b44a5e1e87189d4..5dd1b114f2722ddda9281a5827f86e57eff17e7f 100644 (file)
--- 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;
 }
 
 /* ================================================== */