This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Descriptor passing between process


On Thu, Jan 24, 2002 at 03:17:23PM +0100, Christophe LEITIENNE wrote:
> I found a piece of code that doesn't use all this stuff. Could it work (I
> haven't tried yet) ?
> 
> int sendfd(sockfd, fd)
> int sockfd;  /* UNIX domain socket to pass descriptor on */
> int fd;  /* the actual fd value to pass */
> {
>     struct iovec iov[1];
>     struct msghdr msg;
>     extern int errno;
> 
>     iov[0].iov_base = (char *) 0;  /* no data to send */
>     iov[0].iov_len  = 0;
>     msg.msg_iov          = iov;
>     msg.msg_iovlen       = 1;
>     msg.msg_name         = (caddr_t) 0;
>     msg.msg_accrights    = (caddr_t) &fd; /* address of descriptor */
>     msg.msg_accrightslen = sizeof(fd); /* pass 1 descriptor */
> 
>     if (sendmsg(sockfd, &msg, 0) < 0)
>         return( (errno > 0) ? errno : 255 );
> 
>     return(0);
> }

This isn't supported.  Control structure passing doesn't work at
all with the current implementation.

Btw., the above source code won't work on Linux, too.  First of all,
the msg_accrights and msg_accrightslen members doesn't exist in the 
msghdr struct (they are called msg_control and msg_controllen) and
second, file descriptors in one process have no meaning in another
process, except it's parent or child of the calling process,
coincidentally.  That's somewhat dangerous.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]