|
| 1 | +From acc71340a481ff3ebe339b015f58ae7505fec585 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Takashi Yano < [email protected]> |
| 3 | +Date: Fri, 30 Aug 2024 23:15:44 +0900 |
| 4 | +Subject: [PATCH 83/N] Cygwin: pipe: Restore blocking mode of read pipe on |
| 5 | + close() |
| 6 | + |
| 7 | +If a cygwin app is executed from a non-cygwin app and the cygwin |
| 8 | +app exits, read pipe remains on non-blocking mode because of the |
| 9 | +commit fc691d0246b9. Due to this behaviour, the non-cygwin app |
| 10 | +cannot read the pipe correctly after that. With this patch, the |
| 11 | +blocking mode of the read pipe is stored into was_blocking_read_pipe |
| 12 | +on set_pipe_non_blocking() when the cygwin app starts and restored |
| 13 | +on close(). |
| 14 | + |
| 15 | +Addresses: https://github.com/git-for-windows/git/issues/5115 |
| 16 | +Fixes: fc691d0246b9 ("Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps."); |
| 17 | +Reported-by: isaacag, Johannes Schindelin < [email protected]> |
| 18 | +Reported-at: https://github.com/git-for-windows/git/issues/5115 |
| 19 | +Signed-off-by: Takashi Yano < [email protected]> |
| 20 | +Signed-off-by: Johannes Schindelin < [email protected]> |
| 21 | +--- |
| 22 | + winsup/cygwin/fhandler/pipe.cc | 13 +++++++++++++ |
| 23 | + winsup/cygwin/local_includes/fhandler.h | 1 + |
| 24 | + 2 files changed, 14 insertions(+) |
| 25 | + |
| 26 | +diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc |
| 27 | +index 8daae8d..c47226b 100644 |
| 28 | +--- a/winsup/cygwin/fhandler/pipe.cc |
| 29 | ++++ b/winsup/cygwin/fhandler/pipe.cc |
| 30 | +@@ -54,6 +54,15 @@ fhandler_pipe::set_pipe_non_blocking (bool nonblocking) |
| 31 | + IO_STATUS_BLOCK io; |
| 32 | + FILE_PIPE_INFORMATION fpi; |
| 33 | + |
| 34 | ++ if (get_device () == FH_PIPER && nonblocking && !was_blocking_read_pipe) |
| 35 | ++ { |
| 36 | ++ status = NtQueryInformationFile (get_handle (), &io, &fpi, sizeof fpi, |
| 37 | ++ FilePipeInformation); |
| 38 | ++ if (NT_SUCCESS (status)) |
| 39 | ++ was_blocking_read_pipe = |
| 40 | ++ (fpi.CompletionMode == FILE_PIPE_QUEUE_OPERATION); |
| 41 | ++ } |
| 42 | ++ |
| 43 | + fpi.ReadMode = FILE_PIPE_BYTE_STREAM_MODE; |
| 44 | + fpi.CompletionMode = nonblocking ? FILE_PIPE_COMPLETE_OPERATION |
| 45 | + : FILE_PIPE_QUEUE_OPERATION; |
| 46 | +@@ -94,6 +103,8 @@ fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id) |
| 47 | + even with FILE_SYNCHRONOUS_IO_NONALERT. */ |
| 48 | + set_pipe_non_blocking (get_device () == FH_PIPER ? |
| 49 | + true : is_nonblocking ()); |
| 50 | ++ was_blocking_read_pipe = false; |
| 51 | ++ |
| 52 | + return 1; |
| 53 | + } |
| 54 | + |
| 55 | +@@ -675,6 +686,8 @@ fhandler_pipe::close () |
| 56 | + CloseHandle (query_hdl); |
| 57 | + if (query_hdl_close_req_evt) |
| 58 | + CloseHandle (query_hdl_close_req_evt); |
| 59 | ++ if (was_blocking_read_pipe) |
| 60 | ++ set_pipe_non_blocking (false); |
| 61 | + int ret = fhandler_base::close (); |
| 62 | + ReleaseMutex (hdl_cnt_mtx); |
| 63 | + CloseHandle (hdl_cnt_mtx); |
| 64 | +diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h |
| 65 | +index 15b19f7..f017a6d 100644 |
| 66 | +--- a/winsup/cygwin/local_includes/fhandler.h |
| 67 | ++++ b/winsup/cygwin/local_includes/fhandler.h |
| 68 | +@@ -1193,6 +1193,7 @@ private: |
| 69 | + uint64_t pipename_key; |
| 70 | + DWORD pipename_pid; |
| 71 | + LONG pipename_id; |
| 72 | ++ bool was_blocking_read_pipe; |
| 73 | + void release_select_sem (const char *); |
| 74 | + HANDLE get_query_hdl_per_process (WCHAR *, OBJECT_NAME_INFORMATION *); |
| 75 | + HANDLE get_query_hdl_per_system (WCHAR *, OBJECT_NAME_INFORMATION *); |
0 commit comments