[dovecot-cvs] dovecot/src/lib fdpass.c,1.9,1.10
cras at procontrol.fi
cras at procontrol.fi
Sat Dec 28 21:57:55 EET 2002
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv8843
Modified Files:
fdpass.c
Log Message:
more fixes
Index: fdpass.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/fdpass.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- fdpass.c 28 Dec 2002 19:20:37 -0000 1.9
+++ fdpass.c 28 Dec 2002 19:57:53 -0000 1.10
@@ -48,6 +48,7 @@
struct cmsghdr *cmsg;
char buf[CMSG_SPACE(sizeof(int))];
+ /* at least one byte is required to be sent with fd passing */
i_assert(size > 0 && size < SSIZE_T_MAX);
memset(&msg, 0, sizeof (struct msghdr));
@@ -59,6 +60,7 @@
msg.msg_iovlen = 1;
if (send_fd != -1) {
+ /* set the control and controllen before CMSG_FIRSTHDR() */
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf);
@@ -68,6 +70,8 @@
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
*((int *) CMSG_DATA(cmsg)) = send_fd;
+ /* set the real length we want to use. it's different than
+ sizeof(buf) in 64bit systems. */
msg.msg_controllen = cmsg->cmsg_len;
}
@@ -86,18 +90,21 @@
memset(&msg, 0, sizeof (struct msghdr));
- msg.msg_control = buf;
- msg.msg_controllen = sizeof(buf);
+ iov.iov_base = data;
+ iov.iov_len = size;
+
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
+
+ msg.msg_control = buf;
+ msg.msg_controllen = CMSG_LEN(sizeof(int));
+
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- iov.iov_base = data;
- iov.iov_len = size;
ret = recvmsg(handle, &msg, 0);
- if (msg.msg_controllen != sizeof(buf))
+ if (msg.msg_controllen != CMSG_LEN(sizeof(int)))
*fd = -1;
else
*fd = *(int *) CMSG_DATA(cmsg);
More information about the dovecot-cvs
mailing list