Support monitoring systemd-networkd connectivity.
This commit is contained in:
parent
ef0e3ac22e
commit
f66a343113
1 changed files with 30 additions and 1 deletions
|
@ -65,6 +65,7 @@ dbusThread = do
|
||||||
callback <- asIO1 connchange
|
callback <- asIO1 connchange
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
listenNMConnections client callback
|
listenNMConnections client callback
|
||||||
|
listenNDConnections client callback
|
||||||
listenWicdConnections client callback
|
listenWicdConnections client callback
|
||||||
, do
|
, do
|
||||||
liftAnnex $
|
liftAnnex $
|
||||||
|
@ -88,7 +89,7 @@ dbusThread = do
|
||||||
- are any we can use to monitor network connections. -}
|
- are any we can use to monitor network connections. -}
|
||||||
checkNetMonitor :: Client -> Assistant Bool
|
checkNetMonitor :: Client -> Assistant Bool
|
||||||
checkNetMonitor client = do
|
checkNetMonitor client = do
|
||||||
running <- liftIO $ filter (`elem` [networkmanager, wicd])
|
running <- liftIO $ filter (`elem` manager_addresses)
|
||||||
<$> listServiceNames client
|
<$> listServiceNames client
|
||||||
case running of
|
case running of
|
||||||
[] -> return False
|
[] -> return False
|
||||||
|
@ -99,9 +100,37 @@ checkNetMonitor client = do
|
||||||
]
|
]
|
||||||
return True
|
return True
|
||||||
where
|
where
|
||||||
|
manager_addresses = [networkmanager, networkd, wicd]
|
||||||
networkmanager = "org.freedesktop.NetworkManager"
|
networkmanager = "org.freedesktop.NetworkManager"
|
||||||
|
networkd = "org.freedesktop.network1"
|
||||||
wicd = "org.wicd.daemon"
|
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.
|
{- Listens for NetworkManager connections and diconnections.
|
||||||
-
|
-
|
||||||
- Connection example (once fully connected):
|
- Connection example (once fully connected):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue