X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fsessiond-comm%2Funix.c;h=77a6013f0244572b2c2bb30ae054959db2cdf5c4;hp=48fa1049ac99e6d597e8982bceb5e4cfcf9236fe;hb=1d8d032800b64945d90c7b5a7b8e9316e733a4b1;hpb=17e7527387f4c002b6e20d6b09444ce521f8117f diff --git a/src/common/sessiond-comm/unix.c b/src/common/sessiond-comm/unix.c index 48fa1049a..77a6013f0 100644 --- a/src/common/sessiond-comm/unix.c +++ b/src/common/sessiond-comm/unix.c @@ -17,6 +17,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -92,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. @@ -172,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; @@ -270,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); @@ -397,6 +411,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); @@ -435,6 +452,7 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, struct msghdr msg; struct iovec iov[1]; ssize_t ret; + size_t len_last; #ifdef __linux__ struct cmsghdr *cmptr; size_t sizeof_cred = sizeof(lttng_sock_cred); @@ -461,12 +479,21 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, #endif /* __linux__ */ do { + len_last = iov[0].iov_len; ret = recvmsg(sock, &msg, 0); - } while (ret < 0 && errno == EINTR); + if (ret > 0) { + iov[0].iov_base += ret; + iov[0].iov_len -= ret; + assert(ret <= len_last); + } + } while ((ret > 0 && ret < len_last) || (ret < 0 && errno == EINTR)); if (ret < 0) { PERROR("recvmsg fds"); goto end; + } else if (ret > 0) { + ret = len; } + /* Else ret = 0 meaning an orderly shutdown. */ #ifdef __linux__ if (msg.msg_flags & MSG_CTRUNC) { @@ -539,45 +566,3 @@ int lttcomm_setsockopt_creds_unix_sock(int sock) #else #error "Please implement credential support for your OS." #endif /* __linux__ */ - -/* - * Set socket reciving timeout. - */ -LTTNG_HIDDEN -int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int sec) -{ - int ret; - struct timeval tv; - - tv.tv_sec = sec; - tv.tv_usec = 0; - - ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) { - PERROR("setsockopt SO_RCVTIMEO"); - ret = -errno; - } - - return ret; -} - -/* - * Set socket sending timeout. - */ -LTTNG_HIDDEN -int lttcomm_setsockopt_snd_timeout(int sock, unsigned int sec) -{ - int ret; - struct timeval tv; - - tv.tv_sec = sec; - tv.tv_usec = 0; - - ret = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); - if (ret < 0) { - PERROR("setsockopt SO_SNDTIMEO"); - ret = -errno; - } - - return ret; -}