]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: pipes: don't call NtQueryInformationFile on read side of pipes
authorCorinna Vinschen <corinna@vinschen.de>
Wed, 15 Sep 2021 12:17:59 +0000 (14:17 +0200)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 15 Sep 2021 12:20:03 +0000 (14:20 +0200)
NtQueryInformationFile hangs if it's called on the read side handle of
a pipe while another thread or process is performing a blocking read.

Avoid select potentially hanging by calling NtQueryInformationFile
only on the write side of the pipe and using PeekNamedPipe otherwise.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/select.cc

index a09d8a34da2e5270b040e3100fefbf07a4be1591..566cf66d653bca186ec9a0dc0bf31440bb3e0c18 100644 (file)
@@ -587,6 +587,14 @@ no_verify (select_record *, fd_set *, fd_set *, fd_set *)
 static int
 pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
 {
+  if (fh->get_device () == FH_PIPER)
+    {
+      DWORD nbytes_in_pipe;
+      if (!writing && PeekNamedPipe (h, NULL, 0, NULL, &nbytes_in_pipe, NULL))
+       return nbytes_in_pipe > 0;
+      return -1;
+    }
+
   IO_STATUS_BLOCK iosb = {{0}, 0};
   FILE_PIPE_LOCAL_INFORMATION fpli = {0};
   NTSTATUS status;
This page took 0.031667 seconds and 5 git commands to generate.