public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: /dev/fd/N not synonymous with file descriptor N; it is on Linux
Date: Mon, 28 Jan 2019 16:51:00 -0000	[thread overview]
Message-ID: <20190128165102.GP3912@calimero.vinschen.de> (raw)
In-Reply-To: <c09c2a73bcc7b20fcbcfafe7732053d6@smtp-cloud7.xs4all.net>

[-- Attachment #1: Type: text/plain, Size: 2735 bytes --]

On Jan 28 15:15, Houder wrote:
> On Sun, 27 Jan 2019 22:57:21, Corinna Vinschen  wrote:
> > 
> > On Jan 27 19:39, Houder wrote:
> > > 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.
> > 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.
> [snip]
> 
> Yes Corinna, I already got that from one of your previous replies. You gave
> the same explanation here:
> 
>     https://cygwin.com/ml/cygwin/2019-01/msg00171.html
>     (Date: Tue, 22 Jan 2019 10:41:57 +0100)
> 
>     "A duplicated file handle can't have more permissions than the original
>      handle" (i.e what occurs on pre "Windows 10 1709" systems)
> 
> The "funny" thing is, in that same post, you showed that the STC succeeded
> on your virtual W7 system ... (contradiction!).
> 
> The STC in that post executes the same scenario as above ...
> 
>  - the difference is that the first 3 steps are carried out by bash, when
>    invoked as follows:
> 
>    @@ ./stca /dev/fd/N N<<EOF
> 
> Both STC's (stc.c and stca.c) fail on my W7 (Note: stc.c is the testcase
> that I included in my previous post -- and the one I started this thread
> with).
> 
> Mind this: I am NOT upset that the STC's (plural) fail on (my) W7. Not at
> all!

There was a minor difference when I tested it:  My shell is not bash
but tcsh, and tcsh opens the here document with different perms.

I added debug output to fhandler_base::open and on bash the ACCESS_MASK
set on the incoming handle is 0x12019F with tcsh and 0x120089 with bash.
Compare with https://msdn.microsoft.com/en-us/library/cc246802.aspx, and
you'll see that tcsh opened the file woth O_RDWR, while bash opened the
file with O_RDONLY.

I didn't notice this before, sorry!


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-01-28 16:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-16 16:31 Houder
2018-12-16 20:28 ` Corinna Vinschen
2018-12-16 20:31   ` Corinna Vinschen
2018-12-16 21:36   ` Wayne Davison
2018-12-16 21:55     ` Corinna Vinschen
2018-12-17  4:30       ` Houder
2018-12-17  9:25         ` Corinna Vinschen
2018-12-17 11:26           ` Corinna Vinschen
2019-01-02 13:56             ` Houder
2018-12-17  3:41   ` Houder
2019-01-06 20:19 ` Corinna Vinschen
2019-01-22  8:50   ` Houder
2019-01-22  8:57     ` Houder
2019-01-22  9:06       ` Corinna Vinschen
2019-01-22  9:25         ` Houder
2019-01-22  9:42           ` Corinna Vinschen
2019-01-22 10:20             ` Houder
2019-01-22 10:39               ` Corinna Vinschen
2019-01-27 18:39                 ` Houder
2019-01-27 21:57                   ` Corinna Vinschen
2019-01-27 22:12                     ` Corinna Vinschen
2019-01-28 14:15                     ` Houder
2019-01-28 16:51                       ` Corinna Vinschen [this message]
2019-01-22  9:02     ` Corinna Vinschen
2019-01-22  9:07       ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190128165102.GP3912@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).