avoid crashing in checkDaemon when fcntl locking is not supported

Instead, just assume the daemon isn't running. Since the pid file locking
fails on such a filesystem, we know it's not running.
This commit is contained in:
Joey Hess 2015-11-16 14:27:23 -04:00
parent b5df6c7b93
commit be86081ff4
Failed to extract signature

View file

@ -119,16 +119,18 @@ alreadyRunning = error "Daemon is already running."
- If it's running, returns its pid. -} - If it's running, returns its pid. -}
checkDaemon :: FilePath -> IO (Maybe PID) checkDaemon :: FilePath -> IO (Maybe PID)
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
checkDaemon pidfile = do checkDaemon pidfile = bracket setup cleanup go
v <- catchMaybeIO $ where
setup = catchMaybeIO $
openFd pidfile ReadOnly (Just stdFileMode) defaultFileFlags openFd pidfile ReadOnly (Just stdFileMode) defaultFileFlags
case v of cleanup (Just fd) = closeFd fd
Just fd -> do cleanup Nothing = return ()
go (Just fd) = catchDefaultIO Nothing $ do
locked <- getLock fd (ReadLock, AbsoluteSeek, 0, 0) locked <- getLock fd (ReadLock, AbsoluteSeek, 0, 0)
p <- readish <$> readFile pidfile p <- readish <$> readFile pidfile
closeFd fd `after` return (check locked p) return (check locked p)
Nothing -> return Nothing go Nothing = return Nothing
where
check Nothing _ = Nothing check Nothing _ = Nothing
check _ Nothing = Nothing check _ Nothing = Nothing
check (Just (pid, _)) (Just pid') check (Just (pid, _)) (Just pid')