diff options
author | Sebastian Reuße <seb@wirrsal.net> | 2015-06-02 16:01:57 +0200 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-06-02 12:51:17 -0400 |
commit | 38d9ca99e8f63bdc8fd78e4676f5d696bd131911 (patch) | |
tree | 769a5626b4c544791c241d3e5135a3efb8e8eee4 /Assistant | |
parent | 334954d8bf9113b679f8af29ad481b0daece86f7 (diff) |
Support monitoring systemd-networkd connectivity.
Diffstat (limited to 'Assistant')
-rw-r--r-- | Assistant/Threads/NetWatcher.hs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/Assistant/Threads/NetWatcher.hs b/Assistant/Threads/NetWatcher.hs index 07ccdaf24..52f8db474 100644 --- a/Assistant/Threads/NetWatcher.hs +++ b/Assistant/Threads/NetWatcher.hs @@ -65,6 +65,7 @@ dbusThread = do callback <- asIO1 connchange liftIO $ do listenNMConnections client callback + listenNDConnections client callback listenWicdConnections client callback , do liftAnnex $ @@ -88,7 +89,7 @@ dbusThread = do - are any we can use to monitor network connections. -} checkNetMonitor :: Client -> Assistant Bool checkNetMonitor client = do - running <- liftIO $ filter (`elem` [networkmanager, wicd]) + running <- liftIO $ filter (`elem` manager_addresses) <$> listServiceNames client case running of [] -> return False @@ -99,9 +100,37 @@ checkNetMonitor client = do ] return True where + manager_addresses = [networkmanager, networkd, wicd] networkmanager = "org.freedesktop.NetworkManager" + networkd = "org.freedesktop.network1" wicd = "org.wicd.daemon" +{- Listens for systemd-networkd connections and diconnections. + - + - Connection example (once fully connected): + - [Variant {"OperationalState": Variant "routable"}] + - + - Disconnection example: + - [Variant {"OperationalState": Variant _}] + -} +listenNDConnections :: Client -> (Bool -> IO ()) -> IO () +listenNDConnections client setconnected = + void $ addMatch client matcher + $ \event -> mapM_ handleevent + (map dictionaryItems $ mapMaybe fromVariant $ signalBody event) + where + matcher = matchAny + { matchInterface = Just "org.freedesktop.DBus.Properties" + , matchMember = Just "PropertiesChanged" + } + operational_state_key = toVariant ("OperationalState" :: String) + routable = toVariant $ toVariant ("routable" :: String) + handleevent m = case lookup operational_state_key m of + Just state -> if state == routable + then setconnected True + else setconnected False + Nothing -> noop + {- Listens for NetworkManager connections and diconnections. - - Connection example (once fully connected): |