Skip to content

Commit d750786

Browse files
tyan0dscho
andcommitted
Cygwin: pipe: Add workaround for native ninja
Native (non-cygwin) ninja creates pipe with size == 0, and starts cygwin process with that pipe. This causes infinite loop in the fhandler_fifo_pipe::raw_write(). Ideally, the pipe implementation in cygwin could work even with pipe size == 0, however, it seems impossible due to: (1) select() does not work for that pipe because PeekNamedPipe() always returns 0. Read side is ready to read only when the write side is about to write, but there is no way to know that. (2) The cause of the problem: https://cygwin.com/pipermail/cygwin/2025-January/257143.html cannot be avoidable. To avoid CancelIo() problem, the patch https://cygwin.com/pipermail/cygwin-patches/2025q1/013451.html restricts the data size less than the current pipe space. However, if pipe size is zero this is impossible. This patch adds just a workaround for native ninja that avoid infinite loop in raw_write(). Addresses: msys2/msys2-runtime#270 Reported-by: Christoph Reiter <[email protected]> Co-authored-by: Johannes Schindelin <[email protected]> Reviewed-by: Corinna Vinschen <[email protected]> Signed-off-by: Takashi Yano <[email protected]> (cherry picked from commit 236e865)
1 parent 00e7a89 commit d750786

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

winsup/cygwin/fhandler/pipe.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
455455
ssize_t avail = pipe_buf_size;
456456
bool real_non_blocking_mode = false;
457457

458+
/* Workaround for native ninja. Native ninja creates pipe with size == 0,
459+
and starts cygwin process with that pipe. */
460+
if (avail == 0)
461+
avail = PIPE_BUF;
462+
458463
if (pipe_mtx) /* pipe_mtx is NULL in the fifo case */
459464
{
460465
DWORD timeout = is_nonblocking () ? 0 : INFINITE;

winsup/cygwin/select.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,9 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, int mode)
670670
fpli.WriteQuotaAvailable);
671671
return fpli.WriteQuotaAvailable;
672672
}
673-
/* TODO: Buffer really full or non-Cygwin reader? */
673+
return PIPE_BUF; /* Workaround for native ninja. Native ninja creates
674+
pipe with size == 0, and starts cygwin process
675+
with that pipe. */
674676
}
675677
else if (fpli.ReadDataAvailable)
676678
{

0 commit comments

Comments
 (0)