[newlib-cygwin] Cygwin: FIFO: respect the O_CLOEXEC flag

Ken Brown kbrown@sourceware.org
Tue May 28 20:15:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d79aa0f5939be2640b90971d022b98054b86d249

commit d79aa0f5939be2640b90971d022b98054b86d249
Author: Ken Brown <kbrown@cornell.edu>
Date:   Tue May 28 15:50:05 2019 -0400

    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.

Diff:
---
 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 3fabbc3..c9ff0a3 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);



More information about the Cygwin-cvs mailing list