on master help sign in
setting CloseOnExec to files.
0981091Kazu Yamamoto
warp/Network/Wai/Handler/Warp/FdCache.hs+9−2
@@ -9,6 +9,7 @@ module Network.Wai.Handler.Warp.FdCache (
9#ifndef WINDOWS
9#ifndef WINDOWS
10 , openFile
10 , openFile
11 , closeFile
11 , closeFile
12+ , setFileCloseOnExec
12#endif
13#endif
13 ) where
14 ) where
14
15
@@ -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)
24#endif
25#endif
25import System.Posix.Types (Fd)
26import System.Posix.Types (Fd)
26
27
@@ -70,7 +71,10 @@ inactive (MutableStatus ref) = writeIORef ref Inactive
70data FdEntry = FdEntry !FilePath !Fd !MutableStatus
71data FdEntry = FdEntry !FilePath !Fd !MutableStatus
71
72
72openFile :: FilePath -> IO Fd
73openFile :: FilePath -> IO Fd
74+openFile path = do
73−openFile path = openFd path ReadOnly Nothing defaultFileFlags{nonBlock=False}
75+ fd <- openFd path ReadOnly Nothing defaultFileFlags{nonBlock=False}
76+ setFileCloseOnExec fd
77+ return fd
74
78
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
80
84
85+setFileCloseOnExec :: Fd -> IO ()
86+setFileCloseOnExec fd = setFdOption fd CloseOnExec True
87+
81----------------------------------------------------------------
88----------------------------------------------------------------
82
89
83type FdCache = MMap Hash FdEntry
90type FdCache = MMap Hash FdEntry
warp/Network/Wai/Handler/Warp/Run.hs+1−3
@@ -47,7 +47,6 @@ import System.IO.Error (isFullErrorType, ioeGetErrorType)
47#if WINDOWS
47#if WINDOWS
48import Network.Wai.Handler.Warp.Windows
48import Network.Wai.Handler.Warp.Windows
49#else
49#else
50−import System.Posix.IO (FdOption(CloseOnExec), setFdOption)
51import Network.Socket (fdSocket)
50import Network.Socket (fdSocket)
52#endif
51#endif
53
52
@@ -492,8 +491,7 @@ setSocketCloseOnExec :: Socket -> IO ()
492#if WINDOWS
491#if WINDOWS
493setSocketCloseOnExec _ = return ()
492setSocketCloseOnExec _ = return ()
494#else
493#else
495−setSocketCloseOnExec socket =
494+setSocketCloseOnExec socket = F.setFileCloseOnExec $ fromIntegral $ fdSocket socket
496− setFdOption (fromIntegral $ fdSocket socket) CloseOnExec True
497#endif
495#endif
498
496
499gracefulShutdown :: Counter -> IO ()
497gracefulShutdown :: Counter -> IO ()