From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id E8E463857835; Tue, 14 Sep 2021 15:07:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8E463857835 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 0b538118b2f883919bbf7050d1bf7a978b569a66 X-Git-Newrev: 0063ffeb739189b937097901cca4d5c67e8e5203 Message-Id: <20210914150744.E8E463857835@sourceware.org> Date: Tue, 14 Sep 2021 15:07:44 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Sep 2021 15:07:45 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0063ffeb739189b937097901cca4d5c67e8e5203 commit 0063ffeb739189b937097901cca4d5c67e8e5203 Author: Takashi Yano Date: Sun Sep 12 15:06:05 2021 +0900 Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app. Diff: --- 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) {