smbd: Use msghdr_prep_fds in vfs_aio_fork
authorVolker Lendecke <vl@samba.org>
Wed, 31 Dec 2014 12:03:24 +0000 (13:03 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 5 Jan 2015 23:33:09 +0000 (00:33 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_aio_fork.c

index 39334bc33a52ae964bab8a83bb2b0282a397f6d5..3b6699bd1fa81a885ed8b98ae4c91fb6ca6a62de 100644 (file)
@@ -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));