X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=liblttng-ust-comm%2Flttng-ust-comm.c;h=d213770f7a25f69059810d14d5f12569636cba2b;hb=4ed2398507da76ed80dd09b996242066fa34e2a0;hp=b0e4484abdccfba9078c94d84a46ab744559ca7f;hpb=17ea789c184782cbfa5789c5e644a1774029dcb8;p=lttng-ust.git diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index b0e4484a..d213770f 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -265,7 +265,8 @@ ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) { struct msghdr msg; struct iovec iov[1]; - ssize_t ret; + ssize_t ret = -1; + size_t len_last; memset(&msg, 0, sizeof(msg)); @@ -275,8 +276,14 @@ ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) msg.msg_iovlen = 1; 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) { int shutret; @@ -290,7 +297,10 @@ ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) shutret = shutdown(sock, SHUT_RDWR); if (shutret) ERR("Socket shutdown error"); + } else if (ret > 0) { + ret = len; } + /* ret = 0 means an orderly shutdown. */ return ret; } @@ -367,6 +377,8 @@ ssize_t ustcomm_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 -EINVAL; cmptr->cmsg_level = SOL_SOCKET; cmptr->cmsg_type = SCM_RIGHTS; cmptr->cmsg_len = CMSG_LEN(sizeof_fds); @@ -380,7 +392,7 @@ ssize_t ustcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd) msg.msg_iovlen = 1; do { - ret = sendmsg(sock, &msg, 0); + ret = sendmsg(sock, &msg, MSG_NOSIGNAL); } while (ret < 0 && errno == EINTR); if (ret < 0) { /* @@ -505,19 +517,27 @@ int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, case 0: /* orderly shutdown */ return -EPIPE; case sizeof(*lur): + { + int err = 0; + if (lur->handle != expected_handle) { ERR("Unexpected result message handle: " "expected: %u vs received: %u\n", expected_handle, lur->handle); - return -EINVAL; + err = 1; } if (lur->cmd != expected_cmd) { ERR("Unexpected result message command " "expected: %u vs received: %u\n", expected_cmd, lur->cmd); + err = 1; + } + if (err) { return -EINVAL; + } else { + return lur->ret_code; } - return lur->ret_code; + } default: if (len >= 0) { ERR("incorrect message size: %zd\n", len); @@ -956,6 +976,8 @@ int ustcomm_register_event(int sock, if (len < 0) { return len; } + } else { + free(fields); } if (model_emf_uri_len) {