From d79aa0f5939be2640b90971d022b98054b86d249 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Tue, 28 May 2019 15:50:05 -0400 Subject: [PATCH] Cygwin: FIFO: respect the O_CLOEXEC flag Set the inheritance of the Windows pipe handles according to the O_CLOEXEC flag. Previously the pipe was always created and opened with OBJ_INHERIT. --- winsup/cygwin/fhandler_fifo.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 3fabbc3b4..c9ff0a309 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -176,7 +176,7 @@ fhandler_fifo::create_pipe_instance (bool first) access = GENERIC_READ | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE; sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; - hattr = OBJ_INHERIT; + hattr = openflags & O_CLOEXEC ? 0 : OBJ_INHERIT; if (first) hattr |= OBJ_CASE_INSENSITIVE; InitializeObjectAttributes (&attr, get_pipe_name (), @@ -209,7 +209,8 @@ fhandler_fifo::open_pipe (HANDLE& ph) if (!NT_SUCCESS (status)) return status; access = GENERIC_WRITE | SYNCHRONIZE; - InitializeObjectAttributes (&attr, get_pipe_name (), OBJ_INHERIT, + InitializeObjectAttributes (&attr, get_pipe_name (), + openflags & O_CLOEXEC ? 0 : OBJ_INHERIT, npfsh, NULL); sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; status = NtOpenFile (&ph, access, &attr, &io, sharing, 0);