X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 979653851C22
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1596183040;
	bh=bHxnboqx1saaQMhKNfPf1uxrTj3SHkQwRxnXmDn5N6g=;
	h=Date:From:To:Subject:References:In-Reply-To:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 Reply-To:From;
	b=cH0sywlBrdhmRVHd59aDFTx4thXyEz01g7yZaKYmOzMfwpZmhE6rJjHL8c7Gdgo9F
	 BswdpPbe5KQZblFgP51LXGGx6yXYpcQNQYZPu3pIc3exN+eaN+0eePKfurfo0K303K
	 xg3KVmaNs2WCHL9WzovcEiQZ2Oxbi8kMy7NELKAU=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 05A9A3858D35
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
Date: Fri, 31 Jul 2020 10:10:25 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Synchronization problem with posix_spawn
Message-ID: <20200731081025.GB460314@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <b1992e8b-d2e8-9c44-8f93-a270d5a879ed@cornell.edu>
 <864b3031-9fc8-beb3-ba7c-1ade4c31a288@cornell.edu>
 <20200730115913.GL4206@calimero.vinschen.de>
 <20200730171723.GA460314@calimero.vinschen.de>
 <86051625-646d-065a-8543-1c3086411d3d@cornell.edu>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <86051625-646d-065a-8543-1c3086411d3d@cornell.edu>
X-Provags-ID: V03:K1:aWaEFFeo1DeRElX35OfIUWpZraNLSOCwCB7Wu5v/ZYuJQBECFb2
 wweBEXm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u9SNxKXIMreoeiZWYdOdGbyBpUao13lJcNXTAk6Na3MrbHNf4rBhYI3
 q/NrODZ0AJhtlBWGxSu4M8qZqcwadhqYMaDRpsW7lJa+R5s4wWIoxFCee+DDsx7tHAv6yg329
 K+SbWVu53XHVS2f1+3Dj47Y4QvFcZW4RewU/YumHOsj3GUxv1uJeds/dqj66NKz57LuAptQiG
 iTPWkUnKGUB7GxOMRQq9Ai7AAcX+kvjHWQcOMJWdb0aIUrWJtlGyhcOna09gg06uLgeIpTurK
 j9317/Z2D9HFqeAC4iN/cH7nNE3km2Q4qfubYEKup4YBXwwzcswFmv0kY9cpdMmDrdO+sxws4
 7xQkSR/JLDendYrt4QFdMhVZdKADkU2wJX3PDgyShGThBcVsqGxnyvFGZeOIhhxxgXk2I=
X-Spam-Status: No, score=-99.5 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@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Reply-To: cygwin@cygwin.com
Content-Type: text/plain; charset="utf-8"
Errors-To: cygwin-bounces@cygwin.com
Sender: "Cygwin" <cygwin-bounces@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 06V8B8cg024534

On Jul 30 19:04, Ken Brown via Cygwin wrote:
> Hi Corinna,
> 
> On 7/30/2020 1:17 PM, Corinna Vinschen wrote:
> > Hi Ken,
> > 
> > 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.  Does FreeBSD have the same problem?  Should applications just be
> > > > aware of this issue and insert a sleep after posix_spawn before sending
> > > > signals?
> > > 
> > > Actually, this is a Cygwin problem.  I just had a look into the
> > > newlib implementation myself, and it turns out that the code,
> > > in particular the do_posix_spawn() function, is BSD specific.  It
> > > relies on the BSD implementation of vfork(2).  Cygwin's vfork(2)
> > > on the other hand, is NOT following the historic idea of the
> > > BSD vfork(2), rather it's equivalent to fork(2).  This is
> > > POSIX compliant, but certainly the reliance of the BSD vfork
> > > behaviour makes do_posix_spawn() as it's implemented right now,
> > > not overly functional for Cygwin.
> > > 
> > > 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().
> > If this does the trick (at least your testcase works in my testing),
> > then I'm planning to move the function over to the winsup/cygwin dir
> > so it can be streamlined further.
> > 
> > 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 did a quick test with your new testcase (thanks for that!)
and it seems to be a bit more complicated than I anticipated yesterday.
The parent-child relationship between the processes is broken.  I have
to think a while about this problem, stay tuned.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
--
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

