tech-userlevel archive

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

Re: fcntl & cmsg

On Mon, Sep 22, 2014 at 05:26:47AM +0000, David Holland wrote:
> On Fri, Sep 19, 2014 at 03:38:19PM -0400, James K. Lowden wrote:
>  > unix(4) contains an "interesting" sentence:
>  > 
>  > 	     "The received descriptor is a duplicate of the sender's
>  > descriptor, as if it were created with a call to dup(2).  Per-process
>  > descriptor flags, set with fcntl(2), are not passed to a receiver."
>  > 
>  > because fcntl(2) doesn't define "per-process" descriptor flags.  Does
>  > the sentence mean "any flag set with fcntl", or are some flags
>  > per-process?  If the latter, is the reader supposed to be able to
>  > determine which flags are per-process from the context?  
> I don't know what the documentation is supposed to mean, but the way
> it's supposed to behave is:
>    - fd passing is like calling dup2() except that (once received) the
>      new fd appears in another process;
>    - this means that the close-on-exec flag, which is per file handle,
>      is not shared;
>    - everything else is an attribute of the open file object (or in
>      some cases the vnode, e.g. with F_SETLK or flock()) and should be
>      shared between the two references.

Except that (posix) file locks are per process, not per open file.
This is fubar:
1) you can't lock against another thread in the same process.
2) if another thread opens and closes the same file you lose your locks.


David Laight:

Home | Main Index | Thread Index | Old Index