look for sysctl in some common sbin locations when it's not in PATH
This commit is contained in:
parent
d7289a13e5
commit
6cad247c5f
2 changed files with 12 additions and 5 deletions
|
@ -164,10 +164,11 @@ tooManyWatches hook dir = do
|
||||||
]
|
]
|
||||||
|
|
||||||
querySysctl :: Read a => [CommandParam] -> IO (Maybe a)
|
querySysctl :: Read a => [CommandParam] -> IO (Maybe a)
|
||||||
querySysctl ps = do
|
querySysctl ps = getM go ["sysctl", "/sbin/sysctl", "/usr/sbin/sysctl"]
|
||||||
v <- catchMaybeIO $ readProcess "sysctl" (toCommand ps)
|
where
|
||||||
|
go p = do
|
||||||
|
v <- catchMaybeIO $ readProcess p (toCommand ps)
|
||||||
case v of
|
case v of
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just s -> return $ parsesysctl s
|
Just s -> return $ parsesysctl s
|
||||||
where
|
|
||||||
parsesysctl s = readish =<< lastMaybe (words s)
|
parsesysctl s = readish =<< lastMaybe (words s)
|
||||||
|
|
|
@ -16,6 +16,12 @@ firstM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
|
||||||
firstM _ [] = return Nothing
|
firstM _ [] = return Nothing
|
||||||
firstM p (x:xs) = ifM (p x) (return $ Just x , firstM p xs)
|
firstM p (x:xs) = ifM (p x) (return $ Just x , firstM p xs)
|
||||||
|
|
||||||
|
{- Runs the action on values from the list until it succeeds, returning
|
||||||
|
- its result. -}
|
||||||
|
getM :: Monad m => (a -> m (Maybe b)) -> [a] -> m (Maybe b)
|
||||||
|
getM _ [] = return Nothing
|
||||||
|
getM p (x:xs) = maybe (getM p xs) (return . Just) =<< p x
|
||||||
|
|
||||||
{- Returns true if any value in the list satisfies the predicate,
|
{- Returns true if any value in the list satisfies the predicate,
|
||||||
- stopping once one is found. -}
|
- stopping once one is found. -}
|
||||||
anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
|
anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
|
||||||
|
|
Loading…
Add table
Reference in a new issue