diff options
author | Joey Hess <joey@kitenet.net> | 2012-10-07 17:36:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-10-07 17:36:58 -0400 |
commit | 244a312b17a8ba825507296f52ab9357220102c0 (patch) | |
tree | 8cc4ca37cd0650260f220d4e990af3f4e543c483 /Utility | |
parent | 0605e5eaf6e5745e9c81d335ecf56b996a0b28e5 (diff) | |
parent | 3872945f876941d75d2b188546f9dc4b305cda8c (diff) |
Merge branch 'master' into safesemaphore
Conflicts:
debian/changelog
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/INotify.hs | 11 | ||||
-rw-r--r-- | Utility/Monad.hs | 6 |
2 files changed, 12 insertions, 5 deletions
diff --git a/Utility/INotify.hs b/Utility/INotify.hs index 7934c2446..b55fbc953 100644 --- a/Utility/INotify.hs +++ b/Utility/INotify.hs @@ -164,10 +164,11 @@ tooManyWatches hook dir = do ] querySysctl :: Read a => [CommandParam] -> IO (Maybe a) -querySysctl ps = do - v <- catchMaybeIO $ readProcess "sysctl" (toCommand ps) - case v of - Nothing -> return Nothing - Just s -> return $ parsesysctl s +querySysctl ps = getM go ["sysctl", "/sbin/sysctl", "/usr/sbin/sysctl"] where + go p = do + v <- catchMaybeIO $ readProcess p (toCommand ps) + case v of + Nothing -> return Nothing + Just s -> return $ parsesysctl s parsesysctl s = readish =<< lastMaybe (words s) diff --git a/Utility/Monad.hs b/Utility/Monad.hs index 2c9b9e9e0..6abd7ee5d 100644 --- a/Utility/Monad.hs +++ b/Utility/Monad.hs @@ -16,6 +16,12 @@ firstM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a) firstM _ [] = return Nothing 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, - stopping once one is found. -} anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool |