On Wed, 2 Apr 2025 23:41:46 -0700 (PDT)
Jeremy Drake wrote:
> 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?

Thanks for the suggenstion. That makes sense. I'll submit a fixed version
of the patch.

-- 
Takashi Yano <takashi.y...@nifty.ne.jp>

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

Reply via email to