]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: listener: Fix the build on platforms without MSG_CMSG_CLOEXEC
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 30 Jul 2026 12:03:55 +0000 (14:03 +0200)
committerOlivier Houchard <cognet@ci0.org>
Thu, 30 Jul 2026 12:00:07 +0000 (14:00 +0200)
Some OSes, such as macos, do not provide MSG_CMSG_CLOEXEC, so provide a
fallback mechanism using fdcntl(FD_CLOEXEC) instead.
It doesn't matter right now, that code will never be used on such OS,
because you can't use per-thread-group fd tables in there, but maybe it
will change one day.

include/haproxy/compat.h
src/listener.c

index 39f7af7a69d6a3f898e1951df8e59f7f27f5442f..3f0f0b39307b5979c860989f77f027c59e784b16 100644 (file)
@@ -150,6 +150,14 @@ typedef struct { } empty_t;
 #define MSG_DONTWAIT   0
 #endif
 
+/*
+ * Not every OS defines MSG_CMSG_CLOEXEC, so get a fallback version, to
+ * be tested when using it.
+ */
+#ifndef MSG_CMSG_CLOEXEC
+#define MSG_CMSG_CLOEXEC       0
+#endif
+
 /* Only Linux defines MSG_MORE */
 #ifndef MSG_MORE
 #define MSG_MORE       0
index 29a938090100c0341a3c71ffca711bfef797aafd..7018b08b0653265dae0cd82acb8de2fd4ae9792a 100644 (file)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#include <fcntl.h>
 #include <unistd.h>
 
 #include <import/ist.h>
@@ -969,6 +970,10 @@ void rx_xfer_drain(uint grp)
                if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
                        memcpy(&fd, CMSG_DATA(cmsg), sizeof(int));
 
+               /* platforms with no MSG_CMSG_CLOEXEC get it set by hand */
+               if (!MSG_CMSG_CLOEXEC && fd >= 0)
+                       fcntl(fd, F_SETFD, FD_CLOEXEC);
+
                if (ret != sizeof(xmsg) || fd < 0) {
                        if (fd >= 0)
                                close(fd);