delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/01/27/16:57:36

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=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 AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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=-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 AT cygwin DOT com>
To: cygwin AT cygwin DOT 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 AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <0f030e809f063f5a5e64ff7a7a0c3227 AT xs4all DOT nl> <20190106201950 DOT GC4430 AT calimero DOT vinschen DOT de> <d6431739e2801a80d73e7cb68b4fcc19 AT smtp-cloud8 DOT xs4all DOT net> <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>
MIME-Version: 1.0
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--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019