diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-09-05 11:36:27 +0900 |
---|---|---|
committer | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-11-01 04:50:45 +0900 |
commit | 7ed9adb356df61114bb3fa3d0efc098c0501921c (patch) | |
tree | b097807039dfbdc608f46d4cf751ce4235a96223 /winsup/cygwin/local_includes/fhandler.h | |
parent | 1f05c040599afe63af8c7ecfe71bc461f393600d (diff) | |
download | newlib-7ed9adb356df61114bb3fa3d0efc098c0501921c.zip newlib-7ed9adb356df61114bb3fa3d0efc098c0501921c.tar.gz newlib-7ed9adb356df61114bb3fa3d0efc098c0501921c.tar.bz2 |
Cygwin: pipe: Switch pipe mode to blocking mode by default
Previously, cygwin read pipe used non-blocking mode although non-
cygwin app uses blocking-mode by default. Despite this requirement,
if a cygwin app is executed from a non-cygwin app and the cygwin
app exits, read pipe remains on non-blocking mode because of the
commit fc691d0246b9. Due to this behaviour, the non-cygwin app
cannot read the pipe correctly after that. Similarly, if a non-
cygwin app is executed from a cygwin app and the non-cygwin app
exits, the read pipe mode remains on blocking mode although cygwin
read pipe should be non-blocking mode.
These bugs were provoked by pipe mode toggling between cygwin and
non-cygwin apps. To make management of pipe mode simpler, this
patch has re-designed the pipe implementation. In this new
implementation, both read and write pipe basically use only blocking
mode and the behaviour corresponding to the pipe mode is simulated
in raw_read() and raw_write(). Only when NtQueryInformationFile
(FilePipeLocalInformation) fails for some reasons, the raw_read()/
raw_write() cannot simulate non-blocking access. Therefore, the pipe
mode is temporarily changed to non-blocking mode.
Moreover, because the fact that NtSetInformationFile() in
set_pipe_non_blocking(true) fails with STATUS_PIPE_BUSY if the pipe
is not empty has been found, query handle is not necessary anymore.
This allows the implementation much simpler than before.
Addresses: https://github.com/git-for-windows/git/issues/5115
Fixes: fc691d0246b9 ("Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps.");
Reported-by: isaacag, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>, Ken Brown <kbrown@cornell.edu>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup/cygwin/local_includes/fhandler.h')
-rw-r--r-- | winsup/cygwin/local_includes/fhandler.h | 44 |
1 files changed, 2 insertions, 42 deletions
diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index 5b025f8..4e274d8 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -1197,6 +1197,7 @@ class fhandler_pipe_fifo: public fhandler_base { protected: size_t pipe_buf_size; + HANDLE pipe_mtx; /* Used only in the pipe case */ virtual void release_select_sem (const char *) {}; public: @@ -1209,15 +1210,8 @@ class fhandler_pipe_fifo: public fhandler_base class fhandler_pipe: public fhandler_pipe_fifo { private: - HANDLE read_mtx; pid_t popen_pid; - HANDLE query_hdl; - HANDLE hdl_cnt_mtx; - HANDLE query_hdl_proc; - HANDLE query_hdl_value; - HANDLE query_hdl_close_req_evt; void release_select_sem (const char *); - HANDLE get_query_hdl_per_process (OBJECT_NAME_INFORMATION *); public: fhandler_pipe (); @@ -1234,13 +1228,11 @@ public: int open (int flags, mode_t mode = 0); bool open_setup (int flags); void fixup_after_fork (HANDLE); - void fixup_after_exec (); int dup (fhandler_base *child, int); void set_close_on_exec (bool val); int close (); void raw_read (void *ptr, size_t& len); int ioctl (unsigned int cmd, void *); - int fcntl (int cmd, intptr_t); int fstat (struct stat *buf); int fstatvfs (struct statvfs *buf); int fadvise (off_t, off_t, int); @@ -1265,39 +1257,7 @@ public: fh->copy_from (this); return fh; } - void set_pipe_non_blocking (bool nonblocking); - HANDLE get_query_handle () const { return query_hdl; } - void close_query_handle () - { - if (query_hdl) - { - CloseHandle (query_hdl); - query_hdl = NULL; - } - if (query_hdl_close_req_evt) - { - CloseHandle (query_hdl_close_req_evt); - query_hdl_close_req_evt = NULL; - } - } - bool reader_closed (); - HANDLE temporary_query_hdl (); - bool need_close_query_hdl () - { - return query_hdl_close_req_evt ? - IsEventSignalled (query_hdl_close_req_evt) : false; - } - bool request_close_query_hdl () - { - if (query_hdl_close_req_evt) - { - SetEvent (query_hdl_close_req_evt); - return true; - } - return false; - } - static void spawn_worker (int fileno_stdin, int fileno_stdout, - int fileno_stderr); + NTSTATUS set_pipe_non_blocking (bool nonblocking); }; #define CYGWIN_FIFO_PIPE_NAME_LEN 47 |