bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/3] sendfd, recvf pass file descriptors along Unix domain so


From: Bastien ROUCARIES
Subject: Re: [PATCH 2/3] sendfd, recvf pass file descriptors along Unix domain sockets
Date: Sun, 6 Mar 2011 10:34:45 +0100
User-agent: KMail/1.13.5 (Linux/2.6.37-trunk-amd64; KDE/4.4.5; x86_64; ; )

Le jeudi 3 mars 2011 22:33:21, Eric Blake a écrit :
> 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.

I have it but I have no licence of windows for testing. and do not know if 
cygwin cross compile under linux and run under wine

> > +#ifdef HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44

> > +    (*(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.

Will do

> > +#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

I disagree it is more profound. Typically they are two ways to pass fd:
- one defined in the bsd44 norm (and latter posix)
- one defined in the bsd43 system.

And I suspect testing will reveal some tweak (particularly on old solaris). 

Do you prefer HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY ?

> 
> > +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.

wil run tr. BTW do you know an emacs tweak that convert my tabs to space?

> 
> > +   return -1;
> > +      }
> > +
> > +    fd = *(int *) CMSG_DATA (cmsg);
> 
> Again, memcpy, not type-punning.

Will do

> 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.

Will do

> > +Maintainer:
> > +Bastien ROUCARI�S
> 
> Are you consistently using UTF-8 in your files?  This came through email
> as something rather butchered.

Will do



reply via email to

[Prev in Thread] Current Thread [Next in Thread]