Re: send file descriptor via ipc

From: Robert Watson (rwatson_at_FreeBSD.org)
Date: 02/26/05

  • Next message: Smith III, Edward Mr. CAA/ISC: "RE: sched_4bsd.c Quantum change"
    Date: Sat, 26 Feb 2005 12:04:10 +0000 (GMT)
    To: Yan Yu <yanyu@CS.UCLA.EDU>
    
    

    On Sat, 26 Feb 2005, Yan Yu wrote:

    > I am looking for the function that handle send/recv file descriptors
    > through sendmsg/recvmsg? by looking through source files,
    > unp_internalize/unp_externalize in kern/uipc-usrreq.c seems relevant..
    >
    > but i am not sure since i could not guess the meaning of the function
    > name.. (btw, what is "unp", the prefix in the function name stands
    > for?) Can someone please confirm if it is the right function or point
    > me to the right one i should look at?

    You are indeed looking in the right place.

    When sendmsg() is called with ancillary data, sosend() will copy in the
    ancillary data into an mbuf chain named 'control', which is passed into
    pru_send(). pru_send() for UNIX domain sockets is implemented by
    uipc_send(), which will call unp_internalize() to convert file descriptor
    numbers into 'struct file' references. sbappendcontrol_locked() is used
    to append the the message and ancillary data onto the receive socket
    buffer for the remote socket.

    When recvmsg() is called, soreceive() will retrieve the regular and
    control mbufs from the receive socket buffer. It then calls the protocol
    domain's externalize function, which is implemented by unp_externalize().
    unp_externalize() will extract the 'struct file' references and insert
    them into the file descriptor array of the receiving process.

    One of the complications in this code has to do with unp_gc() -- the
    problem is that when you send a file descriptor over a UNIX domain socket,
    the socket could be closed by both ends before the file descriptor is
    received. If the file descriptor "in transit" is a reference to the UNIX
    domain socket that the file descriptor was sent over, there's a cyclic
    reference. un_gpc() uses a mark-and-sweep graph algorithm to walk the set
    of file descriptors reachable by processes and identify sets of file
    descriptors that are referenced only by disconnected UNIX domain sockets
    so that those sockets can be reclaimed.

    Robert N M Watson

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Smith III, Edward Mr. CAA/ISC: "RE: sched_4bsd.c Quantum change"

    Relevant Pages

    • Re: given an fd, how to tell if its open?
      ... Your process may inherit open fd's from a parent ... like a socket. ... start any new Applix sessions - disastrous with over 400 users over ... up on a consistent file descriptor. ...
      (comp.unix.programmer)
    • Re: Proposal: a revoke() system call
      ... You could achieve something of the same end by opening /dev/null and then dup2'ing to the file descriptor you want to revoke, ... Right now there's a known issue that calling closeon a socket from one thread doesn't interrupt a socket in a blocking I/O call from another thread -- you first have to call shutdown, ... Another example of a "reader thread" would be ... the main thread of a daemon that accepts the incoming connections ...
      (freebsd-arch)
    • Re: How to find a certain socket?
      ... On Wed, 20 Sep 2006, Taras Danko wrote: ... implementation iterates over the "allproc" list and checks every process' file descriptors list to find needed socket. ... The semantics of closing sockets open in processes are a bit tricky -- first off, you really don't want to actually close the file descriptor, as the application may misbehave in rather unfortunate ways, such as writing data to the wrong files, etc. So in that sense, what you're doing is better than actually closing the file descriptor, which would cause that to happen. ...
      (freebsd-hackers)
    • Re: Problem with select() operation...
      ... Is sckt the file descriptor added to the tested ... If this is a TCP socket, ... Append_Circbuf(cbuf, resp); ... out on the selectcommand. ...
      (comp.os.vxworks)
    • Re: [PATCH] fix race in mark_mounts_for_expiry()
      ... >> through a passing a file descriptor, and then the last task which has ... > happens when there are no more references to a vfsmount. ... They're a forest, vfsmnts ... don't move from one tree to another (bind mounts don't link them, ...
      (Linux-Kernel)