From 544292f81d8914b8510f39fe07d2b05cd4e99828 Mon Sep 17 00:00:00 2001 From: "U-EXPRESS5800-S70\\yano" Date: Tue, 16 Nov 2021 20:59:09 +0900 Subject: [PATCH] Cygwin: pipe: Suppress unnecessary set_pipe_non_blocking() call. - Call set_pipe_non_blocking(false) only if the pipe will be really inherited to non-cygwin process. - Set blocking mode properly when cygwin process is executed from non- cygwin process. --- winsup/cygwin/dtable.cc | 3 +++ winsup/cygwin/spawn.cc | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index d57cbb355..e54db4446 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -410,6 +410,9 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) { fhandler_pipe *fhp = (fhandler_pipe *) fh; fhp->set_pipe_buf_size (); + /* Set read pipe always to nonblocking */ + fhp->set_pipe_non_blocking (fhp->get_device () == FH_PIPER ? + true : fhp->is_nonblocking ()); } if (!fh->open_setup (openflags)) diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 6b2026776..e160fa3bb 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -648,8 +648,9 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, if (!iscygwin ()) { + int fd; cfd.rewind (); - while (cfd.next () >= 0) + while ((fd = cfd.next ()) >= 0) if (cfd->get_major () == DEV_PTYS_MAJOR) { fhandler_pty_slave *ptys = @@ -657,13 +658,15 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, ptys->create_invisible_console (); ptys->setup_locale (); } - else if (cfd->get_dev () == FH_PIPEW) + else if (cfd->get_dev () == FH_PIPEW + && (fd == (in__stdout < 0 ? 1 : in__stdout) || fd == 2)) { fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; pipe->close_query_handle (); pipe->set_pipe_non_blocking (false); } - else if (cfd->get_dev () == FH_PIPER) + else if (cfd->get_dev () == FH_PIPER + && fd == (in__stdin < 0 ? 0 : in__stdin)) { fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd; pipe->set_pipe_non_blocking (false); -- 2.33.0