Re: [PATCH v4] Cygwin: pty: Do not transfer input to nat-pipe while masked

Takashi Yano <[email protected]> Thu, 9 Jul 2026 02:15:07 +0900
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
Hi Johannes,

On Wed, 8 Jul 2026 17:01:47 +0200 (CEST)
Johannes Schindelin wrote:
> Hi Takashi,
> 
> On Wed, 8 Jul 2026, Takashi Yano wrote:
> 
> > On the command "cat | non-cygwin-app", `cat` sometimes fails to read
> > key input. This happens when `cat` starts to read input before `non-
> > cygwin-app` configures pseudo console. This is because pipe state is
> > switched to nat-pipe when pseudo console is configured.
> > 
> > This patch prevent the pipe state from changing to nat-pipe state if
> > some cygwin process is reading input from the cyg-pipe.
> > 
> > Fixes: f20641789427 ("Cygwin: pty: Reduce unecessary input transfer.")
> > Signed-off-by: Takashi Yano <[email protected]>
> > Reviewed-by: Johannes Schindelin <[email protected]>
> > ---
> > v2: Release all masks owned by myself on cleanup()
> > v3: Reverts the change that made num_reader and slave_reading shared
> > v4: Correct what mutex shoud be acquired in mask_switch_to_nat_pipe()
> 
> v4 is the right shape. Taking `input_mutex` at the top matches the
> ordering used elsewhere in the file, and because it is a named mutex the
> race is closed across processes attaching to the same tty, not just across
> threads.
> 
> One non-blocking suggestion: As far as I can tell, the new guard is
> correct only because every caller holds `input_mutex`. That is a non-local
> invariant, and a short comment above the guard would help future refactors
> preserve it.

Thanks!

I'll add the comment you suggested and push this patch to master and
cygwin-3_6-branch.

-- 
Takashi Yano <[email protected]>