X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=liblttsessiondcomm%2Fliblttsessiondcomm.c;h=e7e4204339d61dc0b1daa97cdadd3b1c6fd8033c;hp=8fadccf1b884807cfe4ec88e68b6429ec5581eaa;hb=7d8234d9e6f162ee642cdbec911f46c29b012c3d;hpb=82a3637f639486c07ff937ab03e1e9532379d26a diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index 8fadccf1b..e7e420433 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "liblttsessiondcomm.h" @@ -185,6 +186,8 @@ int lttcomm_create_unix_sock(const char *pathname) sun.sun_family = AF_UNIX; strncpy(sun.sun_path, pathname, strlen(pathname)); + /* Unlink the old file if present */ + (void) unlink(pathname); ret = bind(fd, (struct sockaddr *) &sun, sizeof(sun)); if (ret < 0) { perror("bind"); @@ -223,12 +226,10 @@ int lttcomm_listen_unix_sock(int sock) */ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) { - struct msghdr msg; + struct msghdr msg = { 0 }; struct iovec iov[1]; ssize_t ret = -1; - memset(&msg, 0, sizeof(msg)); - iov[0].iov_base = buf; iov[0].iov_len = len; msg.msg_iov = iov; @@ -250,12 +251,10 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) */ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len) { - struct msghdr msg; + struct msghdr msg = { 0 }; struct iovec iov[1]; ssize_t ret = -1; - memset(&msg, 0, sizeof(msg)); - iov[0].iov_base = buf; iov[0].iov_len = len; msg.msg_iov = iov; @@ -294,23 +293,29 @@ int lttcomm_close_unix_sock(int sock) */ ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len) { - struct msghdr msg; + struct msghdr msg = { 0 }; struct cmsghdr *cmptr; struct iovec iov[1]; ssize_t ret = -1; unsigned int sizeof_fds = nb_fd * sizeof(int); char tmp[CMSG_SPACE(sizeof_fds)]; - memset(&msg, 0, sizeof(msg)); + /* + * Note: the consumerd receiver only supports receiving one FD per + * message. + */ + assert(nb_fd == 1); msg.msg_control = (caddr_t)tmp; msg.msg_controllen = CMSG_LEN(sizeof_fds); cmptr = CMSG_FIRSTHDR(&msg); - cmptr->cmsg_len = CMSG_LEN(sizeof_fds); cmptr->cmsg_level = SOL_SOCKET; cmptr->cmsg_type = SCM_RIGHTS; + cmptr->cmsg_len = CMSG_LEN(sizeof_fds); memcpy(CMSG_DATA(cmptr), fds, sizeof_fds); + /* Sum of the length of all control messages in the buffer: */ + msg.msg_controllen = cmptr->cmsg_len; iov[0].iov_base = buf; iov[0].iov_len = len;