X-Recipient: archive-cygwin@delorie.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=jr2MEJ/C2wwkRNDanD47wBesKv3ZC+NqujrNQPUL/wiceaiiBpEWR
	LpQ9wT8qSrq2cepw+u8kODon3MQJUyi1mftZ+Zehhl/i6nN0mY76EoNvk4xzoxfe
	d4Pdz2HyYZ9lYvf++TkFREaaAGnpsIyfwLxvIUdiyvdgVdyh+W8BLQ=
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=epWYmFBoPSzOg79y5kDb/W6F4uQ=; b=jJB4sTT2pIDeV7tHjCnSiF/oFyst
	Nf3EU1fpduRjJ12+bHOqynupt6dh62/5m9KsEQ1p8JmfMJI3rwIMg/kP6GLR94vM
	xCc6rrqcY0ONRY7xyeg7VLODrZX7EyUpOE7/eiKLanm8BUmV34LOMBLLfQCnFZW8
	+YDWq5Es4f6xu0Q=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
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
Date: Sun, 27 Jan 2019 22:57:21 +0100
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
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> <d6431739e2801a80d73e7cb68b4fcc19@smtp-cloud8.xs4all.net> <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)

--sgneBHv3152wZ8jf
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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"

-----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--
