Set the IO manager pipe descriptors to FD_CLOEXEC
authorSimon Marlow <marlowsd@gmail.com>
Thu, 19 Feb 2009 11:42:17 +0000 (11:42 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Thu, 19 Feb 2009 11:42:17 +0000 (11:42 +0000)
This pipe is an internal implementation detail, we don't really want
it to be exposed.

GHC/Conc.lhs
System/Posix/Internals.hs
include/HsBase.h

index 796e4c7..7e8b916 100644 (file)
@@ -1052,6 +1052,8 @@ startIOManagerThread = do
         wr_end <- peekElemOff fds 1
         setNonBlockingFD wr_end -- writes happen in a signal handler, we
                                 -- don't want them to block.
+        setCloseOnExec rd_end
+        setCloseOnExec wr_end
         writeIORef stick (fromIntegral wr_end)
         c_setIOManagerPipe wr_end
         forkIO $ do
index 09243ac..276f841 100644 (file)
@@ -337,6 +337,15 @@ setNonBlockingFD _ = return ()
 #endif
 
 -- -----------------------------------------------------------------------------
+-- Set close-on-exec for a file descriptor
+
+setCloseOnExec :: FD -> IO ()
+setCloseOnExec fd = do
+  throwErrnoIfMinus1 "setCloseOnExec" $
+    c_fcntl_write fd const_f_setfd const_fd_cloexec
+  return ()
+
+-- -----------------------------------------------------------------------------
 -- foreign imports
 
 foreign import ccall unsafe "HsBase.h access"
@@ -519,6 +528,8 @@ foreign import ccall unsafe "HsBase.h __hscore_sig_block"    const_sig_block ::
 foreign import ccall unsafe "HsBase.h __hscore_sig_setmask"  const_sig_setmask :: CInt
 foreign import ccall unsafe "HsBase.h __hscore_f_getfl"      const_f_getfl :: CInt
 foreign import ccall unsafe "HsBase.h __hscore_f_setfl"      const_f_setfl :: CInt
+foreign import ccall unsafe "HsBase.h __hscore_f_setfd"      const_f_setfd :: CInt
+foreign import ccall unsafe "HsBase.h __hscore_fd_cloexec"   const_fd_cloexec :: CLong
 
 #if defined(HTYPE_TCFLAG_T)
 foreign import ccall unsafe "HsBase.h __hscore_sizeof_termios"  sizeof_termios :: Int
index 862cf44..9bbbdc8 100644 (file)
@@ -659,6 +659,26 @@ __hscore_f_setfl( void )
 #endif
 }
 
+INLINE int
+__hscore_f_setfd( void )
+{
+#ifdef F_SETFD
+  return F_SETFD;
+#else
+  return 0;
+#endif
+}
+
+INLINE long
+__hscore_fd_cloexec( void )
+{
+#ifdef FD_CLOEXEC
+  return FD_CLOEXEC;
+#else
+  return 0;
+#endif
+}
+
 // defined in rts/RtsStartup.c.
 extern void* __hscore_get_saved_termios(int fd);
 extern void __hscore_set_saved_termios(int fd, void* ts);