X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust-comm%2Flttng-ust-comm.c;h=5976f6336e0dee543900e6c73881776533e698cf;hb=d32dbe6722a94a6a1cdc0be1335599ceedbaf855;hp=4ed9cc6edc8931061e2cc52fa97964f6bb4d7969;hpb=b2a050e0f805d45fd05315b63a6a344c8588cbad;p=lttng-ust.git diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 4ed9cc6e..5976f633 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -71,6 +71,8 @@ static const char *ustcomm_readable_code[] = { [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_MAGIC) ] = "Invalid magic number", [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_SOCKET_TYPE) ] = "Invalid socket type", [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_UNSUP_MAJOR) ] = "Unsupported major version", + [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PEERCRED) ] = "Cannot get unix socket peer credentials", + [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PEERCRED_PID) ] = "Peer credentials PID is invalid. Socket appears to belong to a distinct, non-nested pid namespace.", }; /* @@ -107,7 +109,7 @@ int ustcomm_connect_unix_sock(const char *pathname, long timeout) * 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, 0); + fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd < 0) { PERROR("socket"); ret = -errno; @@ -122,12 +124,6 @@ int ustcomm_connect_unix_sock(const char *pathname, long timeout) WARN("Error setting connect socket send timeout"); } } - ret = fcntl(fd, F_SETFD, FD_CLOEXEC); - if (ret < 0) { - PERROR("fcntl"); - ret = -errno; - goto error_fcntl; - } memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; @@ -155,7 +151,6 @@ int ustcomm_connect_unix_sock(const char *pathname, long timeout) return fd; error_connect: -error_fcntl: { int closeret; @@ -463,7 +458,7 @@ ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) msg.msg_controllen = sizeof(recv_fd); do { - ret = recvmsg(sock, &msg, 0); + ret = recvmsg(sock, &msg, MSG_CMSG_CLOEXEC); } while (ret < 0 && errno == EINTR); if (ret < 0) { if (errno != EPIPE && errno != ECONNRESET) { @@ -506,7 +501,9 @@ ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) ret = -1; goto end; } + memcpy(fds, CMSG_DATA(cmsg), sizeof_fds); + ret = nb_fd; end: return ret;