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.
*/
#include <errno.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <signal.h>
#include <stdbool.h>
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;