@@ -9,6 +9,7 @@ module Network.Wai.Handler.Warp.FdCache (
99#ifndef WINDOWS
1010 , openFile
1111 , closeFile
12+ , setFileCloseOnExec
1213#endif
1314 ) where
1415
@@ -20,7 +21,7 @@ import Control.Exception (bracket)
2021import Network.Wai.Handler.Warp.IORef
2122import Network.Wai.Handler.Warp.MultiMap
2223import Control.Reaper
23−import System.Posix.IO (openFd, OpenFileFlags(..), defaultFileFlags, OpenMode(ReadOnly), closeFd)
24+import System.Posix.IO (openFd, OpenFileFlags(..), defaultFileFlags, OpenMode(ReadOnly), closeFd, FdOption(CloseOnExec), setFdOption)
2425#endif
2526import System.Posix.Types (Fd)
2627
@@ -70,7 +71,10 @@ inactive (MutableStatus ref) = writeIORef ref Inactive
7071data FdEntry = FdEntry !FilePath !Fd !MutableStatus
7172
7273openFile :: FilePath -> IO Fd
73−openFile path = openFd path ReadOnly Nothing defaultFileFlags{nonBlock=False}
74+openFile path = do
75+ fd <- openFd path ReadOnly Nothing defaultFileFlags{nonBlock=False}
76+ setFileCloseOnExec fd
77+ return fd
7478
7579closeFile :: Fd -> IO ()
7680closeFile = closeFd
@@ -78,6 +82,9 @@ closeFile = closeFd
7882newFdEntry :: FilePath -> IO FdEntry
7983newFdEntry path = FdEntry path <$> openFile path <*> newActiveStatus
8084
85+setFileCloseOnExec :: Fd -> IO ()
86+setFileCloseOnExec fd = setFdOption fd CloseOnExec True
87+
8188----------------------------------------------------------------
8289
8390type FdCache = MMap Hash FdEntry