Commit 8275c414 authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Extend 'lockFile' to return the file descriptor



.. of the locked file so that it can be closed later, if needed.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent f63f7419
......@@ -466,7 +466,7 @@ main _ _ (server, cref, jq) = do
initJQScheduler jq
qlockFile <- jobQueueLockFile
lockFile qlockFile >>= exitIfBad "Failed to obtain the job-queue lock"
_ <- lockFile qlockFile >>= exitIfBad "Failed to obtain the job-queue lock"
qlock <- newMVar ()
finally
......
......@@ -564,11 +564,13 @@ formatOrdinal num
-- | Attempt, in a non-blocking way, to obtain a lock on a given file; report
-- back success.
lockFile :: FilePath -> IO (Result ())
-- Returns the file descriptor so that the lock can be released by closing
lockFile :: FilePath -> IO (Result Fd)
lockFile path = runResultT . liftIO $ do
handle <- openFile path WriteMode
fd <- handleToFd handle
setLock fd (WriteLock, AbsoluteSeek, 0, 0)
return fd
-- | File stat identifier.
type FStat = (EpochTime, FileID, FileOffset)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment