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


Hi all,

> yes, but if i understand things correctly, Christophe was talking
> about passing file descriptors between processes by means of AF_UNIX
> sockets. btw, "Subject:" implies this :).
>
> this is done on unices via msg_control (or msg_accrights) field in msg
> structure. and unices ensure that the process which receives the
> message using recvmsg can use the descriptor for all kinds of file
> operations. in the case of cygwin, the receiver may get the value 3 in
> message packet, but won't be able to use it in "read (3, buf, sizeof
(buf))"

That's exactly what I was talking about.
This is done under Linux or AIX by using a cmsghdr structure and some CMSG_*
macros, which does not appear to be present in Cygwin.
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);
}

Christophe.


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