Fix: ust-comm recvmsg should handle partial receive
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 11 Oct 2013 18:20:22 +0000 (14:20 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 11 Oct 2013 18:20:22 +0000 (14:20 -0400)
Handles cases where unix socket buffer is full. Without this fix, the
session daemon kicks out application that happen to have their
registration message split into multiple recvmsg on the sessiond side.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-comm/lttng-ust-comm.c

index a31786ac52000994feec90a754b5f9ba9701c16c..751ad2e3cf2add1ffd805c9ca4df802034e793b1 100644 (file)
@@ -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;
 }
This page took 0.025412 seconds and 4 git commands to generate.