From: Simon Marlow Date: Thu, 19 Feb 2009 11:42:17 +0000 (+0000) Subject: Set the IO manager pipe descriptors to FD_CLOEXEC X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;ds=sidebyside;h=7451b6856c0302dd926cd0230423840d6cbdced6;p=ghc-base.git Set the IO manager pipe descriptors to FD_CLOEXEC This pipe is an internal implementation detail, we don't really want it to be exposed. --- diff --git a/GHC/Conc.lhs b/GHC/Conc.lhs index 796e4c7..7e8b916 100644 --- a/GHC/Conc.lhs +++ b/GHC/Conc.lhs @@ -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 diff --git a/System/Posix/Internals.hs b/System/Posix/Internals.hs index 09243ac..276f841 100644 --- a/System/Posix/Internals.hs +++ b/System/Posix/Internals.hs @@ -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 diff --git a/include/HsBase.h b/include/HsBase.h index 862cf44..9bbbdc8 100644 --- a/include/HsBase.h +++ b/include/HsBase.h @@ -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);