From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.131]) by sourceware.org (Postfix) with ESMTPS id C32D33858D35 for ; Mon, 3 Aug 2020 11:22:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C32D33858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cygwin.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=corinna-cygwin@cygwin.com Received: from calimero.vinschen.de ([217.91.18.234]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mw9Lw-1ks3D21qGS-00s5UO for ; Mon, 03 Aug 2020 13:22:40 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id C46ADA807C3; Mon, 3 Aug 2020 13:22:39 +0200 (CEST) Date: Mon, 3 Aug 2020 13:22:39 +0200 From: Corinna Vinschen To: cygwin-developers@cygwin.com Subject: Re: Synchronization problem with posix_spawn Message-ID: <20200803112239.GM460314@calimero.vinschen.de> Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: cygwin-developers@cygwin.com References: <864b3031-9fc8-beb3-ba7c-1ade4c31a288@cornell.edu> <20200730115913.GL4206@calimero.vinschen.de> <20200730171723.GA460314@calimero.vinschen.de> <86051625-646d-065a-8543-1c3086411d3d@cornell.edu> <20200731081025.GB460314@calimero.vinschen.de> <20200802115522.GC460314@calimero.vinschen.de> <20200802145054.GE460314@calimero.vinschen.de> <70e56891-fcb0-ba2b-b6de-c29ff1dc970f@cornell.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <70e56891-fcb0-ba2b-b6de-c29ff1dc970f@cornell.edu> X-Provags-ID: V03:K1:jpHP8X+5fFrhqX2++sQZbhebstrPZnXrd86M4aVTAc1mvRatsNP KuDOVsswEv5xJ0VxRwu6WXIu1eXjsjpfDPpIpex3te2tWiSSaDRB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7KyiqItMw== X-Spam-Status: No, score=-99.7 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Aug 2020 11:22:44 -0000 On Aug 2 12:21, Ken Brown via Cygwin-developers wrote: > On 8/2/2020 10:50 AM, Corinna Vinschen wrote: > > On Aug 2 13:55, Corinna Vinschen wrote: > > > [Moving this discussion to cygwin-developers] > > > On Jul 31 10:10, Corinna Vinschen wrote: > > > > On Jul 30 19:04, Ken Brown via Cygwin wrote: > > > > > On 7/30/2020 1:17 PM, Corinna Vinschen wrote: > > > > > > On Jul 30 13:59, Corinna Vinschen wrote: > > > > > > > On Jul 29 19:12, Ken Brown via Cygwin wrote: > > > > > > > > On 7/29/2020 4:17 PM, Ken Brown via Cygwin wrote: > > > > > > > > > posix_spawn(p) returns before the spawned process is fully up and > > > > > > > > > running.  [...] > > > > > > > > I just took a look at the source, and I see that posix_spawn > > > > > > > > was taken from FreeBSD. > > > > > > > > [...] > > > > > > > > > > > > > > Actually, this is a Cygwin problem. > > > > > > > [...] > > > > > > > IOW, we need a Cygwin-specific do_posix_spawn() using fork(2) > > > > > > > in conjunction with some synchronization the BSD function > > > > > > > gets "for free" by using its specific vfork(2). > > > > > > > > > > > > Below is a POC implementation for a Cygwin-specific do_posix_spawn(). > > > > > > [...] > > > > > > Can you give it a try? > > > > > > > > > > It looks like something further is needed: 'wait' doesn't seem to recognize > > > > > the spawned process. > > > > > > > > Oh well. > > > > [...] > > > > > > I attached another patch. This one is designed from the ground up and > > > I *think* it works as desired. I added lots of comments so the idea > > > behind this patch should be clear enough. > > > > > > Please give it a try. > > > > Version 2 of the patch attached. It occured to me belatedly, that > > parent and child have to be synchronized prior to calling WFMO in > > the parent. Otherwise OpenProcess in __posix_spawn_sem_wait_and_close > > may end up opening the exec'ed process rather than the forked child. > > LGTM, and passes all the tests I could throw at it. > > FYI, I noticed the posix_spawn problem because I've been regularly testing > my FIFO code by running the test suite from the "casual" project > (https://bitbucket.org/casualcore/). That project uses FIFOs extensively, > and it also uses posix_spawn. I only realized a few days ago that some of > the test failures I had been seeing had nothing to do with FIFOs but rather > stemmed from the posix_spawn issue that I reported. Those tests now all > pass with your patch. Great, I pushed version 3 of the patch (with an additional minor fix). Can you check this version again, too? > For the sake of my education, could you explain what made you decide that a > semaphore was the right kind of synchronization object for this problem? > (If that doesn't have an easy answer, don't worry about it.) The problem was synchronization plus having a way to propagate an error code up to the parent. The semaphore value can transport information by the fact that it can be set to any value 0 <= X <= INT_MAX. So the semaphore value after WFMO contains the error code "for free". GLibc uses a blocking pipe as synchronization object, as well as transport medium for the error code. I guess I could have done the same, but I don't trust Windows pipes too much... Thanks, Corinna -- Corinna Vinschen Cygwin Maintainer