Fix: define _LGPL_SOURCE in C files
[lttng-tools.git] / src / common / sessiond-comm / unix.c
index fea56e8efa19a404bc1170627ef5300101a39f4a..97537c538b9b28d37cbcbbbe857951b1545ef2a6 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <limits.h>
 #include <stdio.h>
@@ -125,6 +126,11 @@ int lttcomm_create_unix_sock(const char *pathname)
        return fd;
 
 error:
+       if (fd >= 0) {
+               if (close(fd) < 0) {
+                       PERROR("close create unix sock");
+               }
+       }
        return ret;
 }
 
@@ -430,6 +436,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);
@@ -456,12 +463,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) {
@@ -534,45 +550,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;
-}
This page took 0.025064 seconds and 5 git commands to generate.