+2013-12-24 Eric Blake <eblake@redhat.com>
+
+ passfd: give nicer error for recvfd at eof
+ * lib/passfd.c (recvfd): Fake ENOTCONN if other end closes early.
+ * tests/test-passfd.c (main): Enhance test to cover this.
+
2013-12-17 Paul Eggert <eggert@cs.ucla.edu>
gettimeofday: port recent C++ fix to Emacs
struct iovec iov;
struct msghdr msg;
int fd = -1;
+ ssize_t len;
# ifdef CMSG_FIRSTHDR
struct cmsghdr *cmsg;
char buf[CMSG_SPACE (sizeof fd)];
memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
msg.msg_controllen = cmsg->cmsg_len;
- if (recvmsg (sock, &msg, flags_recvmsg) < 0)
+ len = recvmsg (sock, &msg, flags_recvmsg);
+ if (len < 0)
return -1;
cmsg = CMSG_FIRSTHDR (&msg);
/* be paranoiac */
- if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof fd)
+ if (len == 0 || 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 = EACCES;
+ errno = len ? EACCES : ENOTCONN;
return -1;
}
/* father */
else
{
+ ASSERT (close (pair[1]) == 0);
fd = recvfd (pair[0], 0);
if (fd == -1)
{
perror ("fstat");
return 80;
}
+
+ /* Check behavior when sender no longer around */
+ errno = 0;
+ fd = recvfd (pair[0], 0);
+ ASSERT (fd == -1);
+ ASSERT (errno == ENOTCONN);
+
return 0;
}
#else