Re: [PATCH v5] Cygwin: pty: Fix race issue between starting and exiting non-cygwin apps
Takashi Yano <[email protected]> Tue, 23 Jun 2026 23:24:23 +0900
| Newsgroups | gmane.os.cygwin.patches |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 23 Jun 2026 21:29:25 +0900
Takashi Yano wrote:
> > I am a little concerned if the replacement WFSO is equivalent to the
> > looping WFSO being replaced. I.e., it terminates for the same
> > condition(s) with the pty being in correct state. I can't point to
> > something specific though. Can you reassure me? Or is this just
> > re-establishing code to the way it was before?
>
> The code before the patch intended to leave wait-loop when pcon_start
> mode is set even though the pipe_sw_mutex was not acquired. With this
> patch, to_be_read_from_nat_pipe() is not called from master::write()
> anymore, so the busy-loop is not necessary due to changes below.
>
> @@ -2496,7 +2519,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
> @@ -2580,20 +2603,6 @@ fhandler_pty_master::write (const void *ptr, size_t len)
Ah, I forgot to mention.
to_be_read_from_nat_pipe() is called in master::write() below, however,
it is called only when pseudo console is not activated. In this case,
the slave is never in setup_pseudoconsole(). So to_be_read_from_nat_pipe()
can acquire pipe_sw_mutex after a short while.
> > @@ -2383,6 +2373,26 @@ fhandler_pty_master::write (const void *ptr, size_t len)
> >
> > int pcon_start_mode =
> > get_ttyp ()->pcon_start ? 1 : (get_ttyp ()->pcon_start_csi_c ? 2 : 0);
> > +
> > + /* This input transfer is needed when cygwin-app which is started from
> > + non-cygwin app is terminated if pseudo console is disabled. */
> > + if (!get_ttyp ()->pcon_activated && !pcon_start_mode
> > + && to_be_read_from_nat_pipe ())
> > + {
> > + WaitForSingleObject (input_mutex, mutex_timeout);
> > + if (get_ttyp ()->nat_fg (get_ttyp ()->getpgid ())
> > + && get_ttyp ()->pty_input_state == tty::to_cyg)
> > + {
> > + acquire_attach_mutex (mutex_timeout);
> > + fhandler_pty_slave::transfer_input (tty::to_nat, from_master,
> > + get_ttyp (),
> > + input_available_event,
> > + input_transferred_to_cyg);
> > + release_attach_mutex ();
> > + }
> > + ReleaseMutex (input_mutex);
> > + }
> > +
> > if (pcon_start_mode)
> > { /* Reaches here when pseudo console initialization is on going. */
> > /* Pseudo condole support uses "CSI6n" to get cursor position.
--
Takashi Yano <[email protected]>