[ 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.",
};
/*
* 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;
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;
return fd;
error_connect:
-error_fcntl:
{
int closeret;
/*
* Recv a message accompanied by fd(s) from a unix socket.
*
- * Returns the size of received data, or negative error value.
- *
* Expect at most "nb_fd" file descriptors. Returns the number of fd
* actually received in nb_fd.
* Returns -EPIPE on orderly shutdown.
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) {
ret = -1;
goto end;
}
+
memcpy(fds, CMSG_DATA(cmsg), sizeof_fds);
- ret = sizeof_fds;
+
+ ret = nb_fd;
end:
return ret;
}