liblttng-ust-comm/lttng-ust-com.c: remove unnecessary goto in ustcomm_accept_unix_sock()
[lttng-ust.git] / liblttng-ust-comm / lttng-ust-comm.c
index 2332dbf1a383d2b2b6e1500fb604039e53ab72e9..1e2fd1a04395a2f364342d0b5c4d4bf49272489f 100644 (file)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <assert.h>
 #include <errno.h>
+#include <fcntl.h>
 
 #include <ust-comm.h>
 
@@ -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;
@@ -165,13 +172,9 @@ int ustcomm_accept_unix_sock(int sock)
        new_fd = accept(sock, (struct sockaddr *) &sun, &len);
        if (new_fd < 0) {
                perror("accept");
-               goto error;
+               return -1;
        }
-
        return new_fd;
-
-error:
-       return -1;
 }
 
 /*
This page took 0.024017 seconds and 4 git commands to generate.