From 11ba4bcb6479533420c5a5f051efb69998bc7a5d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 20 Feb 2012 22:01:52 -0500 Subject: [PATCH] Use bsd-compatible fcntl for close-on-exec on socket Signed-off-by: Mathieu Desnoyers --- liblttng-ust-comm/lttng-ust-comm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 2332dbf1..078b56a0 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -119,12 +120,17 @@ int ustcomm_connect_unix_sock(const char *pathname) * libust threads require the close-on-exec flag for all * resources so it does not leak file descriptors upon exec. */ - fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + fd = socket(PF_UNIX, SOCK_STREAM, 0); if (fd < 0) { perror("socket"); ret = fd; goto error; } + ret = fcntl(fd, F_SETFD, FD_CLOEXEC); + if (ret < 0) { + perror("fcntl"); + goto error_fcntl; + } memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; @@ -144,6 +150,7 @@ int ustcomm_connect_unix_sock(const char *pathname) return fd; error_connect: +error_fcntl: close(fd); error: return ret; -- 2.34.1