X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=QL2rUeIANHL0pgZGsu9HHrcjLvB3NGab81CNbqaYHZrE68Mf21668 c7ozrnkSHcfW1keB6MZnlr26QCNxa7woOdMVJt/fZMMYnOor9PIjrl4Zg6GgGzdf oDavI+kwGviD750ml/Z+Ncj9iBXl78qBus3uh8om93aW4OIfhRQVVE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=wVXsukojl+xR7yE/CTRG80tstBk=; b=gRpfCX4rTxfEyF8wfSJOZqM9FxO4 kF9wtg5lExBlVm4XFSFTOVQlYqoRBoEXrdf8uqi2Ms9LGv1aBwzWR3VuhczIPk0R Kc6G+D2InwRKzkoViyGgp8JyyTeYQ61lcFo6aKRF95z02GJWfICZY7vcWogAJ4K+ z5BLWfbXgdjqdKQ= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-100.9 required=5.0 tests=BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=UD:aspx X-HELO: mout.kundenserver.de Date: Mon, 28 Jan 2019 17:51:02 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: /dev/fd/N not synonymous with file descriptor N; it is on Linux Message-ID: <20190128165102.GP3912@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <1c60402837d6510667357257b5e96e88 AT xs4all DOT nl> <20190122090633 DOT GK2802 AT calimero DOT vinschen DOT de> <151898514e462bd76cda8a227d4baa16 AT xs4all DOT nl> <20190122094157 DOT GN2802 AT calimero DOT vinschen DOT de> <45382f09a86b6cf3bcabd82adb593622 AT smtp-cloud8 DOT xs4all DOT net> <20190122103928 DOT GO2802 AT calimero DOT vinschen DOT de> <6132284bb44434a89381a695fdd86c7d AT smtp-cloud7 DOT xs4all DOT net> <20190127215721 DOT GH3912 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="VSVNCtZB1QZ8vhj+" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) --VSVNCtZB1QZ8vhj+ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Jan 28 15:15, Houder wrote: > On Sun, 27 Jan 2019 22:57:21, Corinna Vinschen wrote: > >=20 > > 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, c= lose > > > fd > > > - open file once more read-only > > > - unlink file > > > - open file, using /dev/fd/N, read-write <=3D=3D=3D=3D 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" <=3D=3D=3D=3D so ... the file = cannot be > > > written to? > >=20 > > 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] >=20 > Yes Corinna, I already got that from one of your previous replies. You ga= ve > the same explanation here: >=20 > https://cygwin.com/ml/cygwin/2019-01/msg00171.html > (Date: Tue, 22 Jan 2019 10:41:57 +0100) >=20 > "A duplicated file handle can't have more permissions than the origin= al > handle" (i.e what occurs on pre "Windows 10 1709" systems) >=20 > The "funny" thing is, in that same post, you showed that the STC succeeded > on your virtual W7 system ... (contradiction!). >=20 > The STC in that post executes the same scenario as above ... >=20 > - the difference is that the first 3 steps are carried out by bash, when > invoked as follows: >=20 > @@ ./stca /dev/fd/N N<=20 > 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). >=20 > 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 --=20 Corinna Vinschen Cygwin Maintainer --VSVNCtZB1QZ8vhj+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlxPMvYACgkQ9TYGna5E T6CFHA//efU4W0GquHcImyef/xsQxvHZEDA08VQomyF7H1SM6J6anIwlWoGnaMmy hYFvMU2tkNKT8KeysEki0m3uwEE8XGcfjimNV/FwxtALCcBpRPwj08NWKxir8vMO LjAd4FCGTYsDPD3mNgKxrkFFN6jxtlRUxlYxQBA+7YskiJiwL895wtwA4VXR02Hi RYeNUhraDy7cgqok6Y4X5xVySntCvUriEYm0P/6mxP8SoFJaQYjJyvUK573QO8Cd LY3dG6Wvsfo//Rx/lmYCK96bjnGJQLps09xF68GaJ5HxauEowJLXKqqWW+CK9nft Q5RA/AbaJ2vOs6GSFe+XX5+GYTWGPdwHd19vtA7TLw0zeU2GyXNTiJxEB4PH/t6d wIzhN3Sx+2ovNBWtMaz+XqVcHFhAXKj5yGgb2xfSUG+Glykr1ZHmsewD6QBxWhtH wb6g2jp0b1mpAZClTY/NCb9BpYnCcpK5ybEXzwvHRuRDagEwYgCJLVH+xt6hm+uf K0yYIu0T5e4S0747gBfCfjBPY1xP3RPorpGVe2BYBXIQVAZvgQFeuq0mko/sOpmg k9xe+UcLBVodPuKY9D/YFqUWFKxJhQj2sWaRtIMC06axmQL7FB4NEi23mKazTib2 QGNQXPoSHZ6Y7Ra6/EJKvEUfM+4K+MtZUhOHdc1kxlH0oftR1Sg= =vvd6 -----END PGP SIGNATURE----- --VSVNCtZB1QZ8vhj+--