diff options
author | Joey Hess <joey@kitenet.net> | 2014-08-20 17:03:04 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-08-20 17:03:04 -0400 |
commit | 7165e4035e9b6cfeaa5d659341749cc957b27e14 (patch) | |
tree | d78cfbd2483336adb49e82de82efe27c3fc53e7d /Utility | |
parent | 679d9c0027ac996eea9f41a6f0f39af436801e89 (diff) |
more lock file refactoring
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/LockFile/Posix.hs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Utility/LockFile/Posix.hs b/Utility/LockFile/Posix.hs index 1538b491a..b49c5f173 100644 --- a/Utility/LockFile/Posix.hs +++ b/Utility/LockFile/Posix.hs @@ -6,13 +6,16 @@ -} module Utility.LockFile.Posix ( + LockHandle, lockShared, lockExclusive, dropLock, createLockFile, - LockHandle + openExistingLockFile, ) where +import Utility.Exception + import System.IO import System.Posix @@ -35,11 +38,18 @@ lock lockreq mode lockfile = do waitToSetLock l (lockreq, AbsoluteSeek, 0, 0) return (LockHandle l) --- Create and opens lock file, does not lock it. --- Close on exec flag is set so child processes do not inherit the lock. +-- Create and opens lock file; does not lock it. createLockFile :: Maybe FileMode -> LockFile -> IO Fd -createLockFile mode lockfile = do - l <- openFd lockfile ReadWrite mode defaultFileFlags +createLockFile = openLockFile ReadWrite + +-- Opens an existing lock file; does not lock it or create it. +openExistingLockFile :: LockFile -> IO (Maybe Fd) +openExistingLockFile = catchMaybeIO . openLockFile ReadOnly Nothing + +-- Close on exec flag is set so child processes do not inherit the lock. +openLockFile :: OpenMode -> Maybe FileMode -> LockFile -> IO Fd +openLockFile openmode filemode lockfile = do + l <- openFd lockfile openmode filemode defaultFileFlags setFdOption l CloseOnExec True return l |