From 1c929f7d3633d99c0040e51552082829b17f550d Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Sun, 12 Sep 2021 15:06:05 +0900 Subject: [PATCH] Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app. --- winsup/cygwin/fhandler.h | 1 + winsup/cygwin/fhandler_pipe.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index d309be2f7..13fba9a14 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1205,6 +1205,7 @@ public: select_record *select_except (select_stuff *); char *get_proc_fd_name (char *buf); int open (int flags, mode_t mode = 0); + void open_setup (int flags); void fixup_after_fork (HANDLE); int dup (fhandler_base *child, int); int close (); diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc index 6994a5dce..9b4255cfd 100644 --- a/winsup/cygwin/fhandler_pipe.cc +++ b/winsup/cygwin/fhandler_pipe.cc @@ -191,6 +191,19 @@ out: return 0; } +void +fhandler_pipe::open_setup (int flags) +{ + fhandler_base::open_setup (flags); + if (get_dev () == FH_PIPER && !read_mtx) + { + SECURITY_ATTRIBUTES *sa = sec_none_cloexec (flags); + read_mtx = CreateMutex (sa, FALSE, NULL); + if (!read_mtx) + debug_printf ("CreateMutex failed: %E"); + } +} + off_t fhandler_pipe::lseek (off_t offset, int whence) { -- 2.33.0