diff options
author | Daniel Schüssler <933504+DanielSchuessler@users.noreply.github.com> | 2018-08-31 22:41:32 +0200 |
---|---|---|
committer | Daniel Schüssler <933504+DanielSchuessler@users.noreply.github.com> | 2018-10-06 19:54:01 +0200 |
commit | 4b81ed340f586fbc99d7888f8815539dd8e9f517 (patch) | |
tree | 5acb79f2011e02ff1ffb34e249bc998d140d8f66 /src/Main.hs | |
parent | e4bcc59790b4c1650a891c6a4c25e528689c44ac (diff) | |
download | xmobar-4b81ed340f586fbc99d7888f8815539dd8e9f517.tar.gz xmobar-4b81ed340f586fbc99d7888f8815539dd8e9f517.tar.bz2 |
Install signal handlers for most signals that terminate the process by default.
Make the signals throw an exception on the main thread instead (so it can run
cleanup actions, including terminating the other threads cleanly), and
finally run the default signal handler.
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs index 9a3a2e8..64a4ea4 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -38,18 +38,18 @@ import System.Exit import System.Environment import System.FilePath ((</>)) import System.Posix.Files -import Control.Exception import Control.Concurrent.Async (Async, cancel) +import Control.Exception (bracket) import Control.Monad (unless) import Text.Read (readMaybe) -import Signal (setupSignalHandler) +import Signal (setupSignalHandler, withDeferSignals) -- $main -- | The main entry point main :: IO () -main = do +main = withDeferSignals $ do initThreads d <- openDisplay "" args <- getArgs @@ -77,6 +77,7 @@ main = do cleanupThreads :: [[([Async ()], a)]] -> IO () cleanupThreads vars = + -- putStrLn "In cleanupThreads" for_ (concat vars) $ \(asyncs, _) -> for_ asyncs cancel |