This commit is contained in:
Joey Hess 2012-06-11 02:06:22 -04:00
parent d0a0a6ae21
commit 433ff41496

View file

@ -45,9 +45,11 @@ daemonize logfd pidfile changedirectory a = do
lockPidFile :: Bool -> IO () -> FilePath -> IO () lockPidFile :: Bool -> IO () -> FilePath -> IO ()
lockPidFile write onfailure file = do lockPidFile write onfailure file = do
fd <- openFd file ReadWrite (Just stdFileMode) defaultFileFlags fd <- openFd file ReadWrite (Just stdFileMode) defaultFileFlags
when (write) $ void $ locked <- catchMaybeIO $ setLock fd (locktype, AbsoluteSeek, 0, 0)
fdWrite fd =<< show <$> getProcessID case locked of
catchIO (setLock fd (locktype, AbsoluteSeek, 0, 0)) (const onfailure) Nothing -> onfailure
_ -> when write $ void $
fdWrite fd =<< show <$> getProcessID
where where
locktype locktype
| write = WriteLock | write = WriteLock