From 9bd7e52db0386b928a3d777e519ee23f2a0fedfb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 31 Dec 2014 13:03:24 +0100 Subject: [PATCH] smbd: Use msghdr_prep_fds in vfs_aio_fork Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/modules/vfs_aio_fork.c | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c index 39334bc33a5..3b6699bd1fa 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)); -- 2.11.4.GIT