on master help sign in
setting CloseOnExec to files.
commit0981091193b8aaf9d1ad5954faf39ae645c61378 authorKazu Yamamoto <kazu@iij.ad.jp> dateThu 3 Mar 2016, 16:42 (11 years ago) parentaa9571c
2 files changed+10−5
warp/Network/Wai/Handler/Warp/FdCache.hs+9−2 warp/Network/Wai/Handler/Warp/Run.hs+1−3
warp/Network/Wai/Handler/Warp/FdCache.hs+9−2
@@ -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
warp/Network/Wai/Handler/Warp/Run.hs+1−3
@@ -47,7 +47,6 @@ import System.IO.Error (isFullErrorType, ioeGetErrorType)
4747#if WINDOWS
4848import Network.Wai.Handler.Warp.Windows
4949#else
50−import System.Posix.IO (FdOption(CloseOnExec), setFdOption)
5150import Network.Socket (fdSocket)
5251#endif
5352
@@ -492,8 +491,7 @@ setSocketCloseOnExec :: Socket -> IO ()
492491#if WINDOWS
493492setSocketCloseOnExec _ = return ()
494493#else
495−setSocketCloseOnExec socket =
496− setFdOption (fromIntegral $ fdSocket socket) CloseOnExec True
494+setSocketCloseOnExec socket = F.setFileCloseOnExec $ fromIntegral $ fdSocket socket
497495#endif
498496
499497gracefulShutdown :: Counter -> IO ()