aboutsummaryrefslogtreecommitdiff
path: root/Utility/Daemon.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-11 02:06:22 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-11 02:06:22 -0400
commit433ff41496b073c71e465af8b38b2ecafe27d8dd (patch)
tree7d6e1570c996c909d391c8afdaa20dd63599c82d /Utility/Daemon.hs
parentd0a0a6ae21e71c83c6365500a4f9b78f38477ac0 (diff)
bugfix
Diffstat (limited to 'Utility/Daemon.hs')
-rw-r--r--Utility/Daemon.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Utility/Daemon.hs b/Utility/Daemon.hs
index b09dce739..3d2faed67 100644
--- a/Utility/Daemon.hs
+++ b/Utility/Daemon.hs
@@ -45,9 +45,11 @@ daemonize logfd pidfile changedirectory a = do
lockPidFile :: Bool -> IO () -> FilePath -> IO ()
lockPidFile write onfailure file = do
fd <- openFd file ReadWrite (Just stdFileMode) defaultFileFlags
- when (write) $ void $
- fdWrite fd =<< show <$> getProcessID
- catchIO (setLock fd (locktype, AbsoluteSeek, 0, 0)) (const onfailure)
+ locked <- catchMaybeIO $ setLock fd (locktype, AbsoluteSeek, 0, 0)
+ case locked of
+ Nothing -> onfailure
+ _ -> when write $ void $
+ fdWrite fd =<< show <$> getProcessID
where
locktype
| write = WriteLock