Commit e1726045 by Wolfgang Bumiller

af_unix: add lxc_abstract_unix_send_fds_iov

parent cfc3b342
...@@ -153,19 +153,16 @@ int lxc_abstract_unix_connect(const char *path) ...@@ -153,19 +153,16 @@ int lxc_abstract_unix_connect(const char *path)
return fd; return fd;
} }
int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds, int lxc_abstract_unix_send_fds_iov(int fd, int *sendfds, int num_sendfds,
void *data, size_t size) struct iovec *iov, size_t iovlen)
{ {
__do_free char *cmsgbuf = NULL; __do_free char *cmsgbuf = NULL;
int ret; int ret;
struct msghdr msg; struct msghdr msg;
struct iovec iov;
struct cmsghdr *cmsg = NULL; struct cmsghdr *cmsg = NULL;
char buf[1] = {0};
size_t cmsgbufsize = CMSG_SPACE(num_sendfds * sizeof(int)); size_t cmsgbufsize = CMSG_SPACE(num_sendfds * sizeof(int));
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
memset(&iov, 0, sizeof(iov));
cmsgbuf = malloc(cmsgbufsize); cmsgbuf = malloc(cmsgbufsize);
if (!cmsgbuf) { if (!cmsgbuf) {
...@@ -185,10 +182,8 @@ int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds, ...@@ -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)); memcpy(CMSG_DATA(cmsg), sendfds, num_sendfds * sizeof(int));
iov.iov_base = data ? data : buf; msg.msg_iov = iov;
iov.iov_len = data ? size : sizeof(buf); msg.msg_iovlen = iovlen;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
again: again:
ret = sendmsg(fd, &msg, MSG_NOSIGNAL); ret = sendmsg(fd, &msg, MSG_NOSIGNAL);
...@@ -199,6 +194,18 @@ again: ...@@ -199,6 +194,18 @@ again:
return ret; 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, int lxc_unix_send_fds(int fd, int *sendfds, int num_sendfds, void *data,
size_t size) size_t size)
{ {
......
...@@ -35,6 +35,9 @@ extern void lxc_abstract_unix_close(int fd); ...@@ -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_connect(const char *path);
extern int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds, extern int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
void *data, size_t size); 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, extern int lxc_unix_send_fds(int fd, int *sendfds, int num_sendfds, void *data,
size_t size); size_t size);
extern int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds, extern int lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment