@@ -9,6 +9,7 @@ module Network.Wai.Handler.Warp.FdCache (
9#ifndef WINDOWS
9#ifndef WINDOWS
10 , openFile
10 , openFile
11 , closeFile
11 , closeFile
@@ -20,7 +21,7 @@ import Control.Exception (bracket)
20import Network.Wai.Handler.Warp.IORef
21import Network.Wai.Handler.Warp.IORef
21import Network.Wai.Handler.Warp.MultiMap
22import Network.Wai.Handler.Warp.MultiMap
22import Control.Reaper
23import 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)
25import System.Posix.Types (Fd)
26import System.Posix.Types (Fd)
@@ -70,7 +71,10 @@ inactive (MutableStatus ref) = writeIORef ref Inactive
70data FdEntry = FdEntry !FilePath !Fd !MutableStatus
71data FdEntry = FdEntry !FilePath !Fd !MutableStatus
72openFile :: FilePath -> IO Fd
73openFile :: FilePath -> IO Fd
73−openFile path = openFd path ReadOnly Nothing defaultFileFlags{nonBlock=False}
75+ fd <- openFd path ReadOnly Nothing defaultFileFlags{nonBlock=False}
76+ setFileCloseOnExec fd
75closeFile :: Fd -> IO ()
79closeFile :: Fd -> IO ()
76closeFile = closeFd
80closeFile = closeFd
@@ -78,6 +82,9 @@ closeFile = closeFd
78newFdEntry :: FilePath -> IO FdEntry
82newFdEntry :: FilePath -> IO FdEntry
79newFdEntry path = FdEntry path <$> openFile path <*> newActiveStatus
83newFdEntry path = FdEntry path <$> openFile path <*> newActiveStatus
85+setFileCloseOnExec :: Fd -> IO ()
86+setFileCloseOnExec fd = setFdOption fd CloseOnExec True
81----------------------------------------------------------------
88----------------------------------------------------------------
83type FdCache = MMap Hash FdEntry
90type FdCache = MMap Hash FdEntry