/dev/fd/N not synonymous with file descriptor N; it is on Linux

Corinna Vinschen corinna-cygwin@cygwin.com
Sun Jan 27 22:12:00 GMT 2019


On Jan 27 22:57, Corinna Vinschen wrote:
> On Jan 27 19:39, Houder wrote:
> > On Tue, 22 Jan 2019 11:39:28, Corinna Vinschen  wrote:
> > > 
> > > On Jan 22 11:20, Houder wrote:
> > > > On Tue, 22 Jan 2019 10:41:57, Corinna Vinschen  wrote:
> > > > > On Jan 22 10:25, Houder wrote:
> > > > [snip]
> > > >
> > > > > > Curious! It fails (for me) on W7 ...
> > > > >
> > > > > It works for me just as well on W7:
> > [snip]
> > 
> > > Maybe you should run the above shell session under strace and see if
> > > something unusual crops up.  BLODA?
> > 
> > NO BLODA.
> > 
> > Ok, for the record (as this is W7, i.e. pre-pre-W10 :-)
> > 
> > Using my original STC again: (source code included below)
> > 
> >  - create file (in /tmp) write-only, write "Hello, world!" to file, close fd
> >  - open file once more read-only
> >  - unlink file
> >  - open file, using /dev/fd/N, read-write <==== succeeds (and the handle shown by fcntl is read-write)
> >  - write "*****" to file (using the fd obtained in the previous line), lseek to begin of file
> >   - write fails w/ "Permission denied" <==== so ... the file cannot be written to?
> 
> Yes, that scenario fails on W7 but works on W10 1709 and later.  Keep in
> mind that the OS doesn't allow to reopen a file which has been deleted.

... on Windows 8.1 and earlier and (probably, but I can't test this) on
W10 versions prior to 1709.

> Cygwin tries a best effort by duplicating the handle.  A duplicated file
> handle can't have more permissions than the original handle, so if the
> original handle was opened for reading only, the duplicated handle can't
> have write perms.
> [etc]


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20190127/c28e66df/attachment.sig>


More information about the Cygwin mailing list