From 8a53271cd677bea3223f7d25eb1f697aa3d96540 Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Sun, 12 Aug 2012 10:33:41 +0200 Subject: 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. --- src/IPC/DBus.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') 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 -- cgit v1.2.3