+2021-02-16 Bruno Haible <bruno@clisp.org>
+
+ passfd: Fix test failure on FreeBSD >= 12 and NetBSD in 64-bit mode.
+ * lib/passfd.c (recvfd): Use the CMSG_SPACE macro to compute the value
+ for msg_controllen.
+
2021-02-16 Paul Eggert <eggert@cs.ucla.edu>
Port better to macOS Mojave
cmsg->cmsg_len = CMSG_LEN (sizeof fd);
/* Initialize the payload: */
memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
- msg.msg_controllen = cmsg->cmsg_len;
+ msg.msg_controllen = CMSG_SPACE (sizeof fd);
len = recvmsg (sock, &msg, flags_recvmsg);
if (len < 0)
return -1;
-
+ if (len == 0)
+ {
+ /* fake errno: at end the file is not available */
+ errno = ENOTCONN;
+ return -1;
+ }
cmsg = CMSG_FIRSTHDR (&msg);
/* be paranoiac */
- if (len == 0 || cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd)
+ if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd)
|| cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
{
- /* fake errno: at end the file is not available */
- errno = len ? EACCES : ENOTCONN;
+ errno = EACCES;
return -1;
}