summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJochen Keil <jochen.keil@gmail.com>2012-08-12 10:33:41 +0200
committerJochen Keil <jochen.keil@gmail.com>2012-08-12 10:46:31 +0200
commit8a53271cd677bea3223f7d25eb1f697aa3d96540 (patch)
tree8f8f1c3ddc2e2ff0967218e2766105964cba6df8 /src
parent116e902d68546ef7f39ef5f75d24b8beba43661c (diff)
downloadxmobar-8a53271cd677bea3223f7d25eb1f697aa3d96540.tar.gz
xmobar-8a53271cd677bea3223f7d25eb1f697aa3d96540.tar.bz2
Catch error when DBus connection fails
connectSession throws a ClientError Exception when DBUS_SESSION_BUS_ADDRESS is unset. Without exception handler this will result in program termination. Since the DBus handler merely sends a signal to the event loop it does no harm when it won't run. Normal operation will continue just if compiled without dbus support.
Diffstat (limited to 'src')
-rw-r--r--src/IPC/DBus.hs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/IPC/DBus.hs b/src/IPC/DBus.hs
index b0597a4..469a7c6 100644
--- a/src/IPC/DBus.hs
+++ b/src/IPC/DBus.hs
@@ -14,10 +14,14 @@
module IPC.DBus ( runIPC ) where
+import Prelude hiding (catch)
+
import DBus
import DBus.Client
import Control.Monad (join, when)
import Control.Concurrent
+import Control.Exception (catch)
+import System.IO (stderr, hPutStrLn)
import Signal
import Plugins.Utils (safeHead)
@@ -32,10 +36,14 @@ interfaceName :: InterfaceName
interfaceName = interfaceName_ "org.Xmobar.Control"
runIPC :: MVar SignalType -> IO ()
-runIPC mvst = do
- client <- connectSession
- requestName client busName [ nameDoNotQueue ]
- export client objectPath [ sendSignalMethod mvst ]
+runIPC mvst = catch exportConnection printException
+ where
+ printException :: ClientError -> IO ()
+ printException = hPutStrLn stderr . clientErrorMessage
+ exportConnection = do
+ client <- connectSession
+ requestName client busName [ nameDoNotQueue ]
+ export client objectPath [ sendSignalMethod mvst ]
sendSignalMethod :: MVar SignalType -> Method
sendSignalMethod mvst = method interfaceName sendSignalName