Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cygwin: pipe: Restore blocking mode of read pipe on close() #72

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions winsup/cygwin/fhandler/pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ fhandler_pipe::set_pipe_non_blocking (bool nonblocking)
IO_STATUS_BLOCK io;
FILE_PIPE_INFORMATION fpi;

if (get_device () == FH_PIPER && nonblocking && !was_blocking_read_pipe)
{
status = NtQueryInformationFile (get_handle (), &io, &fpi, sizeof fpi,
FilePipeInformation);
if (NT_SUCCESS (status))
was_blocking_read_pipe =
(fpi.CompletionMode == FILE_PIPE_QUEUE_OPERATION);
}

fpi.ReadMode = FILE_PIPE_BYTE_STREAM_MODE;
fpi.CompletionMode = nonblocking ? FILE_PIPE_COMPLETE_OPERATION
: FILE_PIPE_QUEUE_OPERATION;
Expand Down Expand Up @@ -94,6 +103,8 @@ fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode, int64_t uniq_id)
even with FILE_SYNCHRONOUS_IO_NONALERT. */
set_pipe_non_blocking (get_device () == FH_PIPER ?
true : is_nonblocking ());
was_blocking_read_pipe = false;

return 1;
}

Expand Down Expand Up @@ -675,6 +686,8 @@ fhandler_pipe::close ()
CloseHandle (query_hdl);
if (query_hdl_close_req_evt)
CloseHandle (query_hdl_close_req_evt);
if (was_blocking_read_pipe)
set_pipe_non_blocking (false);
int ret = fhandler_base::close ();
ReleaseMutex (hdl_cnt_mtx);
CloseHandle (hdl_cnt_mtx);
Expand Down
1 change: 1 addition & 0 deletions winsup/cygwin/local_includes/fhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ class fhandler_pipe: public fhandler_pipe_fifo
uint64_t pipename_key;
DWORD pipename_pid;
LONG pipename_id;
bool was_blocking_read_pipe;
void release_select_sem (const char *);
HANDLE get_query_hdl_per_process (WCHAR *, OBJECT_NAME_INFORMATION *);
HANDLE get_query_hdl_per_system (WCHAR *, OBJECT_NAME_INFORMATION *);
Expand Down