Mercurial > hg > octave-kai > gnulib-hg
changeset 14508:6bacc85ddf06
passfd: fix incorrect sendmsg arguments
The unit test hung on NetBSD, which pointed out a couple of bugs.
* lib/passfd.c (sendfd): Avoid uninitialized msg_flags field, and
incorrect msg_controllen value.
* modules/passfd-tests (Depends-on): Check for alarm.
* tests/test-passfd.c (main) [HAVE_DECL_ALARM]: Avoid hanging test.
Reported by Bastien ROUCARIES.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Wed, 30 Mar 2011 14:46:02 -0600 |
parents | edeb58356493 |
children | 509ee86b2306 |
files | ChangeLog lib/passfd.c modules/passfd-tests tests/test-passfd.c |
diffstat | 4 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-03-30 Eric Blake <eblake@redhat.com> + + passfd: fix incorrect sendmsg arguments + * lib/passfd.c (sendfd): Avoid uninitialized msg_flags field, and + incorrect msg_controllen value. + * modules/passfd-tests (Depends-on): Check for alarm. + * tests/test-passfd.c (main) [HAVE_DECL_ALARM]: Avoid hanging test. + Reported by Bastien ROUCARIES. + 2011-03-30 Bruno Haible <bruno@clisp.org> c-strcasestr: Relicense under LGPLv2+.
--- a/lib/passfd.c +++ b/lib/passfd.c @@ -47,6 +47,7 @@ struct msghdr msg; /* send at least one char */ + memset (&msg, 0, sizeof msg); iov[0].iov_base = &send; iov[0].iov_len = 1; msg.msg_iov = iov; @@ -67,7 +68,6 @@ cmsg->cmsg_len = CMSG_LEN (sizeof (int)); /* Initialize the payload: */ memcpy (CMSG_DATA (cmsg), &fd, sizeof (fd)); - msg.msg_controllen = cmsg->cmsg_len; #elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY msg.msg_accrights = &fd; msg.msg_accrightslen = sizeof (fd);
--- a/modules/passfd-tests +++ b/modules/passfd-tests @@ -5,6 +5,7 @@ Depends-on: configure.ac: +AC_CHECK_DECLS_ONCE([alarm]) Makefile.am: TESTS += test-passfd
--- a/tests/test-passfd.c +++ b/tests/test-passfd.c @@ -19,6 +19,7 @@ #include "passfd.h" #include <fcntl.h> +#include <signal.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> @@ -40,6 +41,12 @@ int fd; struct stat st; +#if HAVE_DECL_ALARM + /* Avoid hanging on failure. */ + signal (SIGALRM, SIG_DFL); + alarm (5); +#endif + fdnull = open ("/dev/null", O_RDWR); if (fdnull < 0) {