]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: systemd: replace SOCK_CLOEXEC by fcntl call to FD_CLOEXEC
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 20 Nov 2024 12:50:58 +0000 (13:50 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 20 Nov 2024 13:26:23 +0000 (14:26 +0100)
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

index fb36dd993f9dee101b8d58d7458f9378e8aef3c7..64e8e4563150469bf889f079f2542b246e9a419a 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <errno.h>
+#include <fcntl.h>
 #include <inttypes.h>
 #include <signal.h>
 #include <stdbool.h>
@@ -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;