DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5336gtUr3240384
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 5336gtUr3240384
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=eXo24qhW
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF2D8384AB51
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1743662573;
	bh=0VqGqlwiE3VPXx3FcWZLK8USdXN2voi6Z1joHkv1y38=;
	h=Date:To:cc:Subject:In-Reply-To:References:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 From:Reply-To:From;
	b=eXo24qhWQdjKXpnizNtu4lNzBupVL5tBBvVPPhHd5idDohTHwWzJeleAZkm+JEi4h
	 i/CnGk+Z5VClmV5Ear7z1NlDFHVQLBDTNJGu7u+xCqjhF/oXwil+9DqsoIMFW3RnXW
	 TijwFvU7sYcJnrEnUrHlwZoObUXj82BUG3gFuN4Q=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CE95384AB7B
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6CE95384AB7B
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743662507; cv=none;
 b=m3LqdE059g+/G3oAXt9ldDF1fjrZayVhxk52h41EY1nD4Wa9zPZF0uSstX+YUiNJ2MEFOy4kGq43krJHAWQyWY0zgFQ5aQyNq69zbd5fG66D4QGrVw/bi7hpZak0Y8XZP6Mp53nA7/9HxbYQntZCC6nlzEoUsh+w2ZxMSiADk9Q=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1743662507; c=relaxed/simple;
 bh=KBJhRHjrEtBnh5BlgqqY+lTwc/bRG0ZkeISbjy/lTyQ=;
 h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;
 b=t8aDPwkep918g/YQeTcLvdljRw9S34wzJqgHXjwsZ+DFMFC6fjo1DHPcs63mLkuOHZBEf6i5on6nbz6En59fb2Oi+mVnnN62OtQ4CwsbBZTOiFuLoJ/WyNL1fA7fXyZqApu6nsNw56ac0RFpL52NJzJdysOKvQuYC3ztPG006X8=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CE95384AB7B
Date: Wed, 2 Apr 2025 23:41:46 -0700 (PDT)
X-X-Sender: jeremyd@resin.csoft.net
To: Takashi Yano <takashi.yano@nifty.ne.jp>
cc: cygwin@cygwin.com
Subject: Re: Crashes in cmake subprocesses since 3.6.0
In-Reply-To: <20250403144952.ba310b7c6bb82858c489117d@nifty.ne.jp>
Message-ID: <2e7ccec6-922e-8c96-8d28-52d686d81204@jdrake.com>
References: <CAE6_+UfTZc0UTb29p=WVXsP7p7sMmOfmd6SOLR8SCPScJEXHRA@mail.gmail.com>
 <7eaea471-d453-efc7-19cc-58e0ee187af0@jdrake.com>
 <Z-pgTDoHXm9ip53T@calimero.vinschen.de>
 <20250402220125.5d2e1d28cfa37ad934a94ed9@nifty.ne.jp>
 <20250403015216.3a3d48efb51820b23856225c@nifty.ne.jp>
 <Z-1-2raM0AN8aSqD@calimero.vinschen.de>
 <20250403123235.027e508e729188197a96ad2d@nifty.ne.jp>
 <20250403144952.ba310b7c6bb82858c489117d@nifty.ne.jp>
MIME-Version: 1.0
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
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>
From: Jeremy Drake via Cygwin <cygwin@cygwin.com>
Reply-To: Jeremy Drake <cygwin@jdrake.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

On Thu, 3 Apr 2025, Takashi Yano via Cygwin wrote:

> It seems that raw_write() is called before returning from
> pthread::atforkchild() in fork::child().
>
> Moving _my_tls.fixup_after_fork() before atforkchild() seems
> to solve the issue.
>
> What about:
> ld_preload ();
> fixup_hooks_after_fork ();
> ch.rd_proc_pipe = ch.wr_proc_pipe = NULL;
> ?
>
> Should any of these be before pthread::atforkchild() asl well?
>
> I'm now performing a long-run test with the patch:
>
> diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
> index 0742ab363..28daf2682 100644
> --- a/winsup/cygwin/fork.cc
> +++ b/winsup/cygwin/fork.cc
> @@ -187,7 +187,6 @@ frok::child (volatile char * volatile here)
>
>    ForceCloseHandle1 (fork_info->forker_finished, forker_finished);
>
> -  pthread::atforkchild ();
>    cygbench ("fork-child");
>    ld_preload ();
>    fixup_hooks_after_fork ();
> @@ -196,6 +195,7 @@ frok::child (volatile char * volatile here)
>       rd_proc_pipe that would be an invalid handle.  In the case of
>       wr_proc_pipe it would be == my_wr_proc_pipe.  Both would be bad. */
>    ch.rd_proc_pipe = ch.wr_proc_pipe = NULL;
> +  pthread::atforkchild ();
>    CloseHandle (hParent);
>    hParent = NULL;
>    cygwin_finished_initializing = true;

pthread::atforkchild () calls user callbacks, right (pthread_atfork(3))?
Perhaps it should do so after cygwin_finished_initializing is set to
true, in case any functions that the callback might call would be
expecting that?


My encounter with pthread_atfork(3) in the past was an issue in glibc due
to some code that thought it'd be a good idea to mess with atfork handlers
inside an atfork handler.  I can't remember now whether it was registering
a new one, or dlclose-ing a shared library that then caused handlers
registered in that library to be unregistered.  I think the code in
question (in opensc) stopped doing that before glibc got fixed not to
screw up in that scenario.

-- 
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
