]> git.proxmox.com Git - mirror_lxc.git/commitdiff
af_unix: add lxc_abstract_unix_send_fds_iov
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 4 Jul 2019 07:17:04 +0000 (09:17 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 9 Jul 2019 09:13:27 +0000 (11:13 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/lxc/af_unix.c
src/lxc/af_unix.h

index c688a8746f0872bee1b26125132a1cbfd0b092f1..7ab499a4f4ede7229e9b793055dd820891ff092c 100644 (file)
@@ -153,19 +153,16 @@ int lxc_abstract_unix_connect(const char *path)
        return fd;
 }
 
-int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
-                              void *data, size_t size)
+int lxc_abstract_unix_send_fds_iov(int fd, int *sendfds, int num_sendfds,
+                                  struct iovec *iov, size_t iovlen)
 {
        __do_free char *cmsgbuf = NULL;
        int ret;
        struct msghdr msg;
-       struct iovec iov;
        struct cmsghdr *cmsg = NULL;
-       char buf[1] = {0};
        size_t cmsgbufsize = CMSG_SPACE(num_sendfds * sizeof(int));
 
        memset(&msg, 0, sizeof(msg));
-       memset(&iov, 0, sizeof(iov));
 
        cmsgbuf = malloc(cmsgbufsize);
        if (!cmsgbuf) {
@@ -185,10 +182,8 @@ int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
 
        memcpy(CMSG_DATA(cmsg), sendfds, num_sendfds * sizeof(int));
 
-       iov.iov_base = data ? data : buf;
-       iov.iov_len = data ? size : sizeof(buf);
-       msg.msg_iov = &iov;
-       msg.msg_iovlen = 1;
+       msg.msg_iov = iov;
+       msg.msg_iovlen = iovlen;
 
 again:
        ret = sendmsg(fd, &msg, MSG_NOSIGNAL);
@@ -199,6 +194,18 @@ again:
        return ret;
 }
 
+int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
+                              void *data, size_t size)
+{
+       char buf[1] = {0};
+       struct iovec iov = {
+               .iov_base = data ? data : buf,
+               .iov_len = data ? size : sizeof(buf),
+       };
+       return lxc_abstract_unix_send_fds_iov(fd, sendfds, num_sendfds, &iov,
+                                             1);
+}
+
 int lxc_unix_send_fds(int fd, int *sendfds, int num_sendfds, void *data,
                      size_t size)
 {
index 8a068d920fdd1a83ebb19dea5a2996fe44c3eb8f..9f4729c0b9337256ea068860e64fc48094f48e57 100644 (file)
@@ -35,6 +35,9 @@ extern void lxc_abstract_unix_close(int fd);
 extern int lxc_abstract_unix_connect(const char *path);
 extern int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
                                      void *data, size_t size);
+extern int lxc_abstract_unix_send_fds_iov(int fd, int *sendfds,
+                                         int num_sendfds, struct iovec *iov,
+                                         size_t iovlen);
 extern int lxc_unix_send_fds(int fd, int *sendfds, int num_sendfds, void *data,
                             size_t size);
 extern int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,