From b861dc93717c1ab1c0ed440d63f54f58d681da30 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Wed, 20 Nov 2024 13:50:58 +0100 Subject: [PATCH] MINOR: systemd: replace SOCK_CLOEXEC by fcntl call to FD_CLOEXEC Since we build systemd.o for every target, we need it to be more portable. The SOCK_CLOEXEC argument from socket() is not portable and won't build on some OS like macOS X. This patch fixes the issue by replace SOCK_CLOEXEC by a fnctl set to FD_CLOEXEC. --- src/systemd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/systemd.c b/src/systemd.c index fb36dd993f..64e8e45631 100644 --- a/src/systemd.c +++ b/src/systemd.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -87,12 +88,17 @@ int sd_notify(int unset_environment, const char *message) if (socket_addr.sun.sun_path[0] == '@') socket_addr.sun.sun_path[0] = 0; - fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); + fd = socket(AF_UNIX, SOCK_DGRAM, 0); if (fd < 0) { ret = -errno; goto end; } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + ret = -errno; + goto end; + } + if (connect(fd, &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length) != 0) { ret = -errno; goto end;