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
#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"
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
#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);