From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56571 invoked by alias); 27 Jan 2019 21:57:26 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 56558 invoked by uid 89); 27 Jan 2019 21:57:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-105.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=HX-Envelope-From:sk:corinna, H*F:U*corinna-cygwin, permissions, H*r:500 X-HELO: mout.kundenserver.de Received: from mout.kundenserver.de (HELO mout.kundenserver.de) (217.72.192.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 27 Jan 2019 21:57:25 +0000 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N6t3Z-1hFHp727jD-018KGw for ; Sun, 27 Jan 2019 22:57:22 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id B0F4CA8041C; Sun, 27 Jan 2019 22:57:21 +0100 (CET) Date: Sun, 27 Jan 2019 21:57:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: /dev/fd/N not synonymous with file descriptor N; it is on Linux Message-ID: <20190127215721.GH3912@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <0f030e809f063f5a5e64ff7a7a0c3227@xs4all.nl> <20190106201950.GC4430@calimero.vinschen.de> <1c60402837d6510667357257b5e96e88@xs4all.nl> <20190122090633.GK2802@calimero.vinschen.de> <151898514e462bd76cda8a227d4baa16@xs4all.nl> <20190122094157.GN2802@calimero.vinschen.de> <45382f09a86b6cf3bcabd82adb593622@smtp-cloud8.xs4all.net> <20190122103928.GO2802@calimero.vinschen.de> <6132284bb44434a89381a695fdd86c7d@smtp-cloud7.xs4all.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="sgneBHv3152wZ8jf" Content-Disposition: inline In-Reply-To: <6132284bb44434a89381a695fdd86c7d@smtp-cloud7.xs4all.net> User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-01/txt/msg00244.txt.bz2 --sgneBHv3152wZ8jf Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2206 On Jan 27 19:39, Houder wrote: > On Tue, 22 Jan 2019 11:39:28, Corinna Vinschen wrote: > >=20 > > 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] >=20 > > Maybe you should run the above shell session under strace and see if > > something unusual crops up. BLODA? >=20 > NO BLODA. >=20 > Ok, for the record (as this is W7, i.e. pre-pre-W10 :-) >=20 > Using my original STC again: (source code included below) >=20 > - 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 <=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), ls= eek to begin of file > - write fails w/ "Permission denied" <=3D=3D=3D=3D so ... the file cann= ot 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. > Btw, earlier on, when /tmp/stc.txt is unlinked, an "Sharing violation" oc= curs: > 32 21456 [main] stc 1368 unlink_nt: Trying to delete \??\E:\Cygwin64= \tmp\stc.txt, isdir =3D 0 > ----- # Sharing violation? in unlink_nt() in winsup/cygwin/syscalls.cc, a= fter the 3rd call to NtOpenfile() Yes, that's expected. Cygwin first tries to open the file for DELETE only. If that works, it can just delete the file and be done with it. However, if there's any other open handle to the file with more perms than just DELETE, this first call fails with STATUS_SHARING_VIOLATION. Now Cygwin knows that the file is in-use and that the job is not just done with deleting the file. More effort is required. Corinna --=20 Corinna Vinschen Cygwin Maintainer --sgneBHv3152wZ8jf Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlxOKUEACgkQ9TYGna5E T6BRDQ//aekSy6COEVQvfNDYYwNWCN86WE1GibpJYT1Ljw62/40FemJM43w8mUMe KQQ8DgzmmEbvKfdH7UPKxgZdkxijw8MF67RPoOq5zm6G7LcgYa5n18dQWmIgjUw7 FRvjOVphL2BRcFV/sdglB5AptzjxeJgvdqSNY6NI47oeaKHW9bMkhZvvPSFZm/zF G/iqhFVWb417lfRJxMpOZCkrVV6+2Sk9z9aPWZpogXy+iK4T8gAsHkOrvQw+r9JM VvoLIVD0ynWwsCtq5q7jz5iiIK5lOkhFv0dNpQPe8nTH4zPmX1rA4GnNoWBs9BKe KYHV2husQAafUZoDB/oDXjlYto7DSvhdljCvZVYM3Ar7iGGUfIX5uuk3CtRCgloZ dZ2bmhTnYaXDHA2KLjFSNWCL6AzUkvhCuDYd71zzY0BxMWs31uHBxrWdUjNxw+q3 aBVjP5yVhRlFLpYIPQYYjGz4ARbNlNqrbs5OlRfygP2yaFhlZXBFLuA6zvCAxVbR K9J4+kIxughJWDYMKDD5logmkMb36iDmW5siQA+KAH9igDhWbpi+x1AfACVStp8q YZzPIXiFrTwAI+iQzhQ0gOpRjT29Nwh4j1dy+gbRc7ytc5KjXy5l6ZwoHoqUlJ4U 3xcsvCZwUehDY4F2/A0K0Umi+f8N9ZByYosLWYmgA3BGd1c92G4= =pNj3 -----END PGP SIGNATURE----- --sgneBHv3152wZ8jf--