Skip to content

Commit b861dc9

Browse files
committed
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.
1 parent 1ceeeac commit b861dc9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/systemd.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <errno.h>
13+
#include <fcntl.h>
1314
#include <inttypes.h>
1415
#include <signal.h>
1516
#include <stdbool.h>
@@ -87,12 +88,17 @@ int sd_notify(int unset_environment, const char *message)
8788
if (socket_addr.sun.sun_path[0] == '@')
8889
socket_addr.sun.sun_path[0] = 0;
8990

90-
fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
91+
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
9192
if (fd < 0) {
9293
ret = -errno;
9394
goto end;
9495
}
9596

97+
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
98+
ret = -errno;
99+
goto end;
100+
}
101+
96102
if (connect(fd, &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length) != 0) {
97103
ret = -errno;
98104
goto end;

0 commit comments

Comments
 (0)