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:message-id:from:reply-to:to:subject :references:in-reply-to:content-type; q=dns; s=default; b=VhnK/1 xTrtdbyGmgp89acDDgHTSYeW+A8oFtpf4VS3LtPgPO9WSWTdjnlHuJoTo8cvkMut u27yxqhwZ6LhZNRkr3ePGTMqUFp+1PEDOAFcqL+eP46wsYmNRBn760LxEQ8rB7pb 1+Y7w3ys21XWvVqGRSEiHnNfadNFA8KCGpnrs= 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:message-id:from:reply-to:to:subject :references:in-reply-to:content-type; s=default; bh=xCuavC8HRk3O AdpEA6OE4RsFzKo=; b=UeDESVRVZ189cV5JY5SOqugwMhB+aX7/7nnmeCsZq/8t CnTrUCCaWRS3GMKCIHZOXF4P+ncBKJffCpQO/HDNcUa4WNTgSzq4aFpFazj7J1CX 2NOpdCcr6eLNDVgAyzhPTGMD7HOH+EJGzKo3dVa+BMGJsGQFjKvw+kImMtpvM/M= 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=-7.6 required=5.0 tests=BAYES_00,GIT_PATCH_2,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=D*vinschen.de, sk:corinna, replies, disposition X-HELO: lb1-smtp-cloud7.xs4all.net Date: Mon, 28 Jan 2019 15:15:35 +0100 Message-ID: From: Houder Reply-To: 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 References: <0f030e809f063f5a5e64ff7a7a0c3227 AT xs4all DOT nl> <20190106201950 DOT GC4430 AT calimero DOT vinschen DOT de> <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> In-Reply-to: <20190127215721.GH3912@calimero.vinschen.de> Content-Type: text/plain; charset=UTF-8; format=fixed User-Agent: mua.awk 0.99 X-IsSubscribed: yes 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< Tue, 8 Jan 2019 20:37:43 +0000 (21:37 +0100) committer Corinna Vinschen Tue, 8 Jan 2019 20:47:28 +0000 (21:47 +0100) commit ec36c59f1a9349e690849e393251623f5936408c tree fd8b12b24bdb4fb21a4600cdd0dd14d4e91fb30d tree parent 0c545f3264aaaac3d02d3ef785a2e2e9d77ed03f commit | diff Cygwin: open: workaround reopen file w/ delete disposition set On pre-W10 systems there's no way to reopen a file by handle if the delete disposition is set. We try to get around with duplicating the handle. 535 /* Open system call handler function. */ 536 int 537 fhandler_base::open (int flags, mode_t mode) 538 { .. 694 status = NtCreateFile (&fh, access, &attr, &io, NULL, file_attributes, shared, 695 create_disposition, options, p, plen); 696 /* Pre-W10, we can't open a file by handle with delete disposition 697 set, so we have to lie our ass off. */ 698 if (get_handle () && status == STATUS_DELETE_PENDING) 699 { 700 BOOL ret = DuplicateHandle (GetCurrentProcess (), get_handle (), 701 GetCurrentProcess (), &fh, 702 access, !(flags & O_CLOEXEC), 0); 703 if (!ret) 704 ret = DuplicateHandle (GetCurrentProcess (), get_handle (), 705 GetCurrentProcess (), &fh, 706 0, !(flags & O_CLOEXEC), 707 DUPLICATE_SAME_ACCESS); 708 if (!ret) 709 debug_printf ("DuplicateHandle after STATUS_DELETE_PENDING, %E"); 710 else 711 status = STATUS_SUCCESS; 712 } ===== -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple