delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/04/20/14:47:47

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C5FF3857739
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1682016420;
bh=lvTY/V9YqLpzrv9oyKh84qyLVC7T22Q+3st+mOygR70=;
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=jXLgg+g40JdLxS/sczUXqwLxfxq0yX17KCP4A1XZTl/mrTbHfggdD9jQnMTW13Fva
yfLFU/1HXF77w42FiRgMy7OkyVGzDVWDwtYtUiNe2kYUrNApyfdY8vFZkIgECfTPWN
+mAIlwEzXtlQ36qqnvwQhyxLCKEPrO1kST24M4fM=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C11283858D37
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-Spam-Language: en
X-Spam-Relay-Country:
X-Spam-DCC: B=MGTINTERNET; R=smtp1.atof.net 1170; Body=1 Fuz1=1 Fuz2=1
X-Spam-RBL:
X-Spam-PYZOR: Reported 0 times.
Date: Thu, 20 Apr 2023 14:46:21 -0400
To: Bruno Haible <bruno AT clisp DOT org>, cygwin AT cygwin DOT com
Subject: Re: posix_spawn facility
Message-ID: <ZEGIfeYzimEAYwDt@xps13>
References: <1752276 DOT 7aRn1RRit1 AT nimes> <ZEFKW/rbAS8x4QbV AT calimero DOT vinschen DOT de>
<ZEFO9ELNzIliSGPv AT calimero DOT vinschen DOT de> <4892432 DOT 0VBMTVartN AT nimes>
<ZEFdBAODKA2c61pg AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
In-Reply-To: <ZEFdBAODKA2c61pg@calimero.vinschen.de>
X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS,
SPF_HELO_NONE, SPF_PASS, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: "gs-cygwin.com--- via Cygwin" <cygwin AT cygwin DOT com>
Reply-To: gs-cygwin DOT com AT gluelogic DOT com
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 33KIlP0R007599

On Thu, Apr 20, 2023 at 05:40:52PM +0200, Corinna Vinschen via Cygwin wrote:
> On Apr 20 16:58, Bruno Haible via Cygwin wrote:
> > Corinna Vinschen wrote:
> > > > Hmm.  Your code uses lpReserved2 for that, but the functionality is
> > > > one implemented in MSVCRT.  For obvious reasons, Cygwin executables
> > > > are not linked against msvcrt.dll and we're using lpReserved2 for our
> > > > own purposes.
> > > 
> > > Oh, btw., did you know that there's a newer mechanism for defining
> > > specific inheritable handles to CreateProcess, which is implemented
> > > in kernel32.dll, so it does not depend on MSVCRT?
> > > 
> > > There's a STARTUPINFOEX structure which allows to specify the 
> > > additional handles.  See
> > > 
> > > https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-startupinfoexa
> > > 
> > > and the PROC_THREAD_ATTRIBUTE_HANDLE_LIST argument described in
> > > 
> > > https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute
> > 
> > Indeed, this appears to be a more "official" way to pass handles for fd ≥ 3,
> > instead of lpReserved2 — albeit without associated 'flags'. Not sure how
> > O_APPEND is handled then...
> 
> Yeah, theoretically, that should be handled by CreateFile opening the
> file with FILE_APPEND_DATA attribute, and in the child MSVCRT should
> test with NtQueryInformationFile(FILE_ACCESS_INFORMATION) if the
> FILE_APPEND_DATA flag is set.
> 
> But then again, if MSVCRT implements fcntl (F_SETFL) to allow
> manipulating the O_APPEND flag... unfortunately there's no such
> operation via Win32 or native calls.  That would require to reopen the
> file with different access mask and replace the HANDLE under the hood of
> the descriptor.  I'm not aware if and how MSVCRT performs this action.

If you are carefully controlling and allowing an explicit set of file
handles to be inherited, and the entire program uses this interface to
create new processes, then you can safely _sopen_s() or otherwise to
create new handles, pass them to CreateProcess() using STARTUPINFOEX,
and then close any new handles created solely for inheritance in child.

Cheers, Glenn

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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