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.
#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
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <fcntl.h>
#include <unistd.h>
#include <import/ist.h>
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);