delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/01/24/09:17:55

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <000901c1a4e1$d967f430$010310ac@lyoncleitienne>
From: "Christophe LEITIENNE" <cleitienne AT wanadoo DOT fr>
To: "egor duda" <cygwin AT cygwin DOT com>
References: <002401c1a3f4$0b77e8c0$010310ac AT lyoncleitienne> <20020123120701 DOT A11608 AT cygbert DOT vinschen DOT de> <8181418335 DOT 20020124161420 AT logos-m DOT ru> <20020124142156 DOT Y11608 AT cygbert DOT vinschen DOT de> <4183271981 DOT 20020124164513 AT logos-m DOT ru>
Subject: Re: Descriptor passing between process
Date: Thu, 24 Jan 2002 15:17:23 +0100
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019