summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSibi Prabakaran <sibi@psibi.in>2020-05-19 11:37:19 +0530
committerSibi Prabakaran <sibi@psibi.in>2020-05-19 11:37:19 +0530
commited0663aac942113a693e225dbacaa69784017976 (patch)
treec58689f6c3154d7350a2d9bd1726952d19c5b332
parent16d1240ab8cd2502400c5ef1e4434654df8a2e1c (diff)
downloadxmobar-ed0663aac942113a693e225dbacaa69784017976.tar.gz
xmobar-ed0663aac942113a693e225dbacaa69784017976.tar.bz2
Add EOF check before getLine operation from stdin
Fixes https://github.com/jaor/xmobar/issues/442
-rw-r--r--src/Xmobar/Plugins/StdinReader.hs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Xmobar/Plugins/StdinReader.hs b/src/Xmobar/Plugins/StdinReader.hs
index bc4bb5f..8c0c0bf 100644
--- a/src/Xmobar/Plugins/StdinReader.hs
+++ b/src/Xmobar/Plugins/StdinReader.hs
@@ -22,21 +22,31 @@ import Prelude
import System.Posix.Process
import System.Exit
import System.IO
-import Control.Exception (SomeException(..), handle)
import Xmobar.Run.Exec
import Xmobar.X11.Actions (stripActions)
+import Xmobar.System.Utils (onSomeException)
data StdinReader = StdinReader | UnsafeStdinReader
deriving (Read, Show)
instance Exec StdinReader where
start stdinReader cb = do
- s <- handle (\(SomeException e) -> do hPrint stderr e; return "") getLine
- cb $ escape stdinReader s
+ -- The EOF check is necessary for certain systems
+ -- More details here https://github.com/jaor/xmobar/issues/442
eof <- isEOF
if eof
- then exitImmediately ExitSuccess
- else start stdinReader cb
+ then do
+ hPrint stderr $ "xmobar: eof at an early stage"
+ exitImmediately ExitSuccess
+ else return ()
+ s <-
+ getLine `onSomeException`
+ (\e -> do
+ let errorMessage = "xmobar: Received exception " <> show e
+ hPrint stderr errorMessage
+ cb errorMessage)
+ cb $ escape stdinReader s
+ start stdinReader cb
escape :: StdinReader -> String -> String
escape StdinReader = stripActions