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