X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fsessiond-comm%2Funix.c;h=e2d0def8e842f2eb156d82178a71ca3be148f96c;hp=97537c538b9b28d37cbcbbbe857951b1545ef2a6;hb=8bbffd547a5d7ce11413aff2082f97aafe9d7a51;hpb=6c1c0768320135c6936c371b09731851b508c023 diff --git a/src/common/sessiond-comm/unix.c b/src/common/sessiond-comm/unix.c index 97537c538..e2d0def8e 100644 --- a/src/common/sessiond-comm/unix.c +++ b/src/common/sessiond-comm/unix.c @@ -93,6 +93,16 @@ int lttcomm_accept_unix_sock(int sock) return new_fd; } +LTTNG_HIDDEN +int lttcomm_create_anon_unix_socketpair(int *fds) +{ + if (socketpair(PF_UNIX, SOCK_STREAM, 0, fds) < 0) { + PERROR("socketpair"); + return -1; + } + return 0; +} + /* * Creates a AF_UNIX local socket using pathname bind the socket upon creation * and return the fd. @@ -173,7 +183,7 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) do { len_last = iov[0].iov_len; - ret = recvmsg(sock, &msg, 0); + ret = recvmsg(sock, &msg, MSG_NOSIGNAL); if (ret > 0) { iov[0].iov_base += ret; iov[0].iov_len -= ret; @@ -271,6 +281,9 @@ ssize_t lttcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd) msg.msg_controllen = CMSG_LEN(sizeof_fds); cmptr = CMSG_FIRSTHDR(&msg); + if (!cmptr) { + return -1; + } cmptr->cmsg_level = SOL_SOCKET; cmptr->cmsg_type = SCM_RIGHTS; cmptr->cmsg_len = CMSG_LEN(sizeof_fds); @@ -383,10 +396,11 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len) size_t sizeof_cred = sizeof(lttng_sock_cred); char anc_buf[CMSG_SPACE(sizeof_cred)]; lttng_sock_cred *creds; + + memset(anc_buf, 0, CMSG_SPACE(sizeof_cred) * sizeof(char)); #endif /* __linux__ */ memset(&msg, 0, sizeof(msg)); - memset(anc_buf, 0, CMSG_SPACE(sizeof_cred) * sizeof(char)); iov[0].iov_base = buf; iov[0].iov_len = len; @@ -398,6 +412,9 @@ ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len) msg.msg_controllen = CMSG_LEN(sizeof_cred); cmptr = CMSG_FIRSTHDR(&msg); + if (!cmptr) { + return -1; + } cmptr->cmsg_level = SOL_SOCKET; cmptr->cmsg_type = LTTNG_SOCK_CREDS; cmptr->cmsg_len = CMSG_LEN(sizeof_cred);