diff options
author | 2012-04-11 20:28:01 -0400 | |
---|---|---|
committer | 2012-04-11 20:28:01 -0400 | |
commit | 1f34bf9acb3efa191e4f09f7e2f300cd759262a3 (patch) | |
tree | 1ea1dcb30664f416036c9e2e63ac099873109165 /Utility/Inotify.hs | |
parent | b133a76f96a340c98f5698ca991e9433165c0817 (diff) |
add waitForTermination
Diffstat (limited to 'Utility/Inotify.hs')
-rw-r--r-- | Utility/Inotify.hs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Utility/Inotify.hs b/Utility/Inotify.hs index bf3681468..56906466b 100644 --- a/Utility/Inotify.hs +++ b/Utility/Inotify.hs @@ -1,14 +1,19 @@ +{-# LANGUAGE CPP #-} + module Utility.Inotify where import Common hiding (isDirectory) import System.INotify import qualified System.Posix.Files as Files +import System.Posix.Terminal +import Control.Concurrent.MVar +import System.Posix.Signals -demo :: IO String +demo :: IO () demo = withINotify $ \i -> do watchDir i add del "/home/joey/tmp/me" putStrLn "started" - getLine -- wait for exit + waitForTermination where add file = putStrLn $ "add " ++ file del file = putStrLn $ "del " ++ file @@ -64,3 +69,16 @@ watchDir' scan i add del dir = do go (MovedOut { isDirectory = False, filePath = f }) = del <@> f go (Deleted { isDirectory = False, filePath = f }) = del <@> f go _ = return () + +{- Pauses the main thread, letting children run until program termination. -} +waitForTermination :: IO () +waitForTermination = do + mv <- newEmptyMVar + check softwareTermination mv + whenM (queryTerminal stdInput) $ + check keyboardSignal mv + takeMVar mv + where + check sig mv = do + installHandler sig (CatchOnce $ putMVar mv ()) Nothing + return () |