On 03/01/2011 07:04 AM, Bastien ROUCARIES wrote: > Recvfd and sendfd can be used to pass an open file descriptor over a Unix > domain socket from one process to another.
Have you considered porting this to Windows yet? I like the idea of this module (especially since I want to use it in libvirt), but it's not ready for prime-time yet. > +#ifdef HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44 > + struct cmsghdr *cmsg; > + char buf[CMSG_SPACE (sizeof (fd))]; > + > + msg.msg_control = buf; > + msg.msg_controllen = sizeof (buf); > + cmsg = CMSG_FIRSTHDR (&msg); > + cmsg->cmsg_level = SOL_SOCKET; > + cmsg->cmsg_type = SCM_RIGHTS; > + cmsg->cmsg_len = CMSG_LEN (sizeof (int)); > + /* Initialize the payload: */ > + (*(int *) CMSG_DATA (cmsg)) = fd; You need to use memcpy here, as CMSG_DATA does not have type alignment guarantees, and your type-punning may result in SIGBUS on some architectures. > +#elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43 This #define name is awkward to read because it is platform-based rather than feature based. Why not use AC_CHECK_MEMBER's paradigm of HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS > +recvfd (int sock) > + > + if (recvmsg (sock, &msg, 0) < 0) > + return -1; > + > + cmsg = CMSG_FIRSTHDR (&msg); > + /* be paranoiac */ > + if (cmsg == NULL || cmsg->cmsg_len != CMSG_LEN (sizeof (int)) > + || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) > + { > + /* fake errno: at end the file is not available */ > + errno = EACCES; No TABS, please. > + return -1; > + } > + > + fd = *(int *) CMSG_DATA (cmsg); Again, memcpy, not type-punning. I just created http://sourceware.org/bugzilla/show_bug.cgi?id=12539 - it would be nice if the kernel and glibc would give us a way to atomically set the FD_CLOEXEC flag on fd's created by recvfd. But even without atomic support from the kernel, it would be nice for gnulib to provide provide something like recvfd2(int sock, int flags), where flags can be O_CLOEXEC (or maybe SOCK_CLOEXEC), as a way to set it as soon as possible after receiving the fd, in anticipation of the kernel catching up and providing such an interface. > +Maintainer: > +Bastien ROUCARI�S Are you consistently using UTF-8 in your files? This came through email as something rather butchered. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature