From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.20]) by sourceware.org (Postfix) with ESMTPS id A46F73858D37 for ; Thu, 20 Apr 2023 10:19:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A46F73858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=clisp.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=clisp.org ARC-Seal: i=1; a=rsa-sha256; t=1681985940; cv=none; d=strato.com; s=strato-dkim-0002; b=ry9mp7PVqyXXct59WsMGybWkrDAg5/6Y4WOXpuGAk4NKzRe6G/Lsor88P8lDIj/93G Vlehc8iSCV9g7JbVrAgPnusDjS9mx9C+dxmCBbyQOgeTbZt5IC9Hz+OVB1u5xtS+kkOx nivj00lawtdNjrpRe81bFWZ/g+/tEFESTcQbntINdjZWA5LOGwWNapSU4Wk117S+Dqfl WD0Qye3IDqPr1LNrSUw5qdTib0ldeqhOjMTuSgY6Y/KDCj2rLquNVRBkmv4NaNaq1X+3 V315cdZPVvcvKpQphrAetdKE5x/V+XMPeqiAnawiVVSKcIjBrIIN6qfxBbthaqJGcXCC /UhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1681985940; s=strato-dkim-0002; d=strato.com; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=R2PtNyFR2x3h+LDaFSji3Lt5AineOx8yhJS6Eq56p88=; b=sQIfKNeS66axmYWwjcVlyv8pQtqnlpt1YSg6kuBXRYfV9TPtQ0M1fj5/FjSE3+9iNS RsenPLd663SK1kk5xWHTiJK8iDYi5qVjd+r2B9eE0LW8d4uOZpk2E/TPm8h3KphhghOQ vdTwwYHXMNBRyKlOVOenbh/r7VI1+OJqfL5S/AWYhbt9PZ5uc90fXlLnQLKfFty9La1u e1imwNPqJur7gSsIDH0v7Hq5IiPOGjRVc5biYbUfHVOSH8RyC9bzBbYgiulSU3X0dkPX T+igEg4NggnHBTjvIzb8Iz8O1NO6JhiKIKaGsWTlFdmoa9esgUACbgafYUcYATD89wcr U2Tg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1681985940; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=R2PtNyFR2x3h+LDaFSji3Lt5AineOx8yhJS6Eq56p88=; b=jujReKopgUKXZGCRDJ41StBwyk2zSEgQjbfaQj2TC+ffamdfEqxiMK8Axbigr1/Yml ygBIKSEECg1ZUGDN/ExUG63x3KI2BjpixESG0qHJGpk1I2mfkxNhb5pT442o5us0Caj0 IAIBRWrkqbd9D3L6jTQL1nCAFCOGiFuO2r/VujGLzbkDqTguF7zGvVH860Bss5mzBw66 0bXDMTAPEQTrXfDME5byPqArFU2sO0w/XQCS25jokE3jlBVVIm4aBjGQUZP0bW6dbN1c aJl3FqEoUYXKFUWgsjZMNvG2R8fTNzf8B5jLJ6T7SwdgfsiZg38Sb0c30szrBleQvH2c RaGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1681985940; s=strato-dkim-0003; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Cc:Date: From:Subject:Sender; bh=R2PtNyFR2x3h+LDaFSji3Lt5AineOx8yhJS6Eq56p88=; b=ve9Y6njG/wlx5jfjLhtHlH1OQDNlXyVRJ+8aJ6SingpYUjQ63lIBFrYTdLI9fN2Ymp cVWSdh4Or6r3oGC3B1Dg== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPDj/1vgIuvkaOwJLsXaUZx50Vobw==" Received: from nimes.localnet by smtp.strato.de (RZmta 49.4.0 AUTH) with ESMTPSA id D064b6z3KAJ0h2F (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Thu, 20 Apr 2023 12:19:00 +0200 (CEST) From: Bruno Haible To: cygwin@cygwin.com Cc: gs-cygwin.com@gluelogic.com Subject: Re: posix_spawn facility Date: Thu, 20 Apr 2023 12:18:59 +0200 Message-ID: <1853259.CQOukoFCf9@nimes> In-Reply-To: References: <1752276.7aRn1RRit1@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Corinna Vinschen wrote: > Unfortunately you can't expect any noticable difference on Cygwin by > using posix_spawn. While Cygwin has a spawn() family of functions, we > don't (and can't... yet) use them. > > The problem is that we don't have a safe way to perform the spawn > attributes and file actions which are supposed to be performed between > the fork() and the exec() step when using the spawn() functions. This > would have to be implemented first. So, you are saying that on Cygwin, spawnvpe() and friends are fast, because child_info_spawn::worker ends up calling CreateProcessW rather immediately? But posix_spawn is slow, because it goes another path, through fork()? If that's the case, it might help to look at how I created Gnulib's posix_spawn for native Windows: 1) Extend the spawnvpe function to a spawnvpech function. It takes additional arguments - const char *currdir - int currdirfd - HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle (The latter is because the first 3 file descriptors are passed specially on Windows.) 2) Refactor the guts of spawnvpech, moving as much as possible into helper functions. In my case, spawnvpech shrunk to only 150 lines of code. The helper functions, in the native Windows case, were: - prepare_spawn - compose_command - compose_envblock - init_inheritable_handles, compose_handles_block, free_inheritable_handles - convert_CreateProcess_error See https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/windows-spawn.h . I would expect that similar helper functions can be created in Cygwin. The "inheritable handles" is a data structure that allows for the arbitrary reshuffling of file descriptors required by posix_spawn (the addopen, adddup2, addclose actions), i.e. which does the book- keeping which HANDLE must in the end be open in the parent and which must in the end be open in the child, and at which position. While at the same time optimizing the number of DuplicateHandle calls. Without this optimization, the code is simpler, but there were many redundant DuplicateHandle calls. This data structure is essential for posix_spawn[p] to be multithread- safe. posix_spawn[p] must not modify the file descriptors of the parent; instead it has to create the planned file descriptors for the child in memory. During this refactoring, it is essential to have a good test suite. Because when you make a mistake and leave a fd / HANDLE accidentally open (in the parent or in the child), applications that invoke a pipe start to hang. 3) With these helper functions, write a new core for posix_spawn[p]. In my case, it was less than 250 lines of code, which is not straightforward, but also not really hard either. See https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/spawni.c lines 610..852. At this step, you can use Gnulib's test suite for verifying that the new code works properly. Hope this helps. Bruno