summaryrefslogtreecommitdiffstats
path: root/source3/modules
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-12-31 13:03:24 +0100
committerJeremy Allison <jra@samba.org>2015-01-06 00:33:09 +0100
commit9bd7e52db0386b928a3d777e519ee23f2a0fedfb (patch)
tree907a416548c4888e0c38a74aee702f4b39ecd1a1 /source3/modules
parentbd9b59ae28e8128857e7d8308a23d09a547299e0 (diff)
smbd: Use msghdr_prep_fds in vfs_aio_fork
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'source3/modules')
-rw-r--r--source3/modules/vfs_aio_fork.c39
1 files changed, 9 insertions, 30 deletions
diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index 39334bc33a..3b6699bd1f 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -28,6 +28,7 @@
#include "lib/util/tevent_unix.h"
#include "lib/sys_rw.h"
#include "lib/sys_rw_data.h"
+#include "lib/msghdr.h"
#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS)
# error Can not pass file descriptors
@@ -220,40 +221,18 @@ static ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
static ssize_t write_fd(int fd, void *ptr, size_t nbytes, int sendfd)
{
- struct msghdr msg;
- struct iovec iov[1];
-
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
- union {
- struct cmsghdr cm;
- char control[CMSG_SPACE(sizeof(int))];
- } control_un;
- struct cmsghdr *cmptr;
-
- ZERO_STRUCT(msg);
- ZERO_STRUCT(control_un);
-
- msg.msg_control = control_un.control;
- msg.msg_controllen = sizeof(control_un.control);
-
- cmptr = CMSG_FIRSTHDR(&msg);
- cmptr->cmsg_len = CMSG_LEN(sizeof(int));
- cmptr->cmsg_level = SOL_SOCKET;
- cmptr->cmsg_type = SCM_RIGHTS;
- memcpy(CMSG_DATA(cmptr), &sendfd, sizeof(sendfd));
-#else
- ZERO_STRUCT(msg);
- msg.msg_accrights = (caddr_t) &sendfd;
- msg.msg_accrightslen = sizeof(int);
-#endif
+ struct msghdr msg;
+ size_t bufsize = msghdr_prep_fds(NULL, NULL, 0, &sendfd, 1);
+ uint8_t buf[bufsize];
+ struct iovec iov;
+ msghdr_prep_fds(&msg, buf, bufsize, &sendfd, 1);
msg.msg_name = NULL;
msg.msg_namelen = 0;
- ZERO_STRUCT(iov);
- iov[0].iov_base = (void *)ptr;
- iov[0].iov_len = nbytes;
- msg.msg_iov = iov;
+ iov.iov_base = (void *)ptr;
+ iov.iov_len = nbytes;
+ msg.msg_iov = &iov;
msg.msg_iovlen = 1;
return (sendmsg(fd, &msg, 0));