From fc691d0246b95807cd2fac83cceb8053fc295eb2 Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Mon, 11 Mar 2024 22:08:00 +0900 Subject: Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps. If pipe reader is a non-cygwin app first, and cygwin process reads the same pipe after that, the pipe has been set to bclocking mode for the cygwin app. However, the commit 9e4d308cd592 assumes the pipe for cygwin process always is non-blocking mode. With this patch, the pipe mode is reset to non-blocking when cygwin app is started. Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255644.html Fixes: 9e4d308cd592 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT flag for read pipe.") Reported-by: wh Reviewed-by: Corinna Vinschen Signed-off-by: Takashi Yano --- winsup/cygwin/spawn.cc | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'winsup/cygwin/spawn.cc') diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 71d75bb..3da7708 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -580,38 +580,8 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, int fileno_stderr = 2; if (!iscygwin ()) - { - bool need_send_sig = false; - int fd; - cygheap_fdenum cfd (false); - while ((fd = cfd.next ()) >= 0) - if (cfd->get_dev () == FH_PIPEW - && (fd == fileno_stdout || fd == fileno_stderr)) - { - fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; - pipe->set_pipe_non_blocking (false); - if (pipe->request_close_query_hdl ()) - need_send_sig = true; - } - else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin) - { - fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; - pipe->set_pipe_non_blocking (false); - } - - if (need_send_sig) - { - tty_min dummy_tty; - dummy_tty.ntty = (fh_devices) myself->ctty; - dummy_tty.pgid = myself->pgid; - tty_min *t = cygwin_shared->tty.get_cttyp (); - if (!t) /* If tty is not allocated, use dummy_tty instead. */ - t = &dummy_tty; - /* Emit __SIGNONCYGCHLD to let all processes in the - process group close query_hdl. */ - t->kill_pgrp (__SIGNONCYGCHLD); - } - } + fhandler_pipe::spawn_worker (fileno_stdin, fileno_stdout, + fileno_stderr); bool no_pcon = mode != _P_OVERLAY && mode != _P_WAIT; term_spawn_worker.setup (iscygwin (), handle (fileno_stdin, false), -- cgit v1.1