diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 9f2828920..3e9f9a0d3 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -101,7 +101,7 @@ void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd) if (!lockFile(lockFd.get(), ltWrite, false)) { printInfo("waiting for exclusive access to the Nix store for ca drvs..."); - lockFile(lockFd.get(), ltNone, false); // We have acquired a shared lock; release it to prevent deadlocks + unlockFile(lockFd.get()); // We have acquired a shared lock; release it to prevent deadlocks lockFile(lockFd.get(), ltWrite, true); } @@ -321,7 +321,7 @@ LocalStore::LocalStore(LocalStoreConfig config) if (!lockFile(globalLock.get(), ltWrite, false)) { printInfo("waiting for exclusive access to the Nix store..."); - lockFile(globalLock.get(), ltNone, false); // We have acquired a shared lock; release it to prevent deadlocks + unlockFile(globalLock.get()); // We have acquired a shared lock; release it to prevent deadlocks lockFile(globalLock.get(), ltWrite, true); } diff --git a/lix/libstore/pathlocks.cc b/lix/libstore/pathlocks.cc index 8c990ef4a..38d179f45 100644 --- a/lix/libstore/pathlocks.cc +++ b/lix/libstore/pathlocks.cc @@ -41,14 +41,13 @@ bool lockFile(int fd, LockType lockType, bool wait) int type; if (lockType == ltRead) type = LOCK_SH; else if (lockType == ltWrite) type = LOCK_EX; - else if (lockType == ltNone) type = LOCK_UN; else abort(); if (wait) { while (flock(fd, type) != 0) { checkInterrupt(); if (errno != EINTR) - throw SysError("acquiring/releasing lock"); + throw SysError("acquiring lock"); else return false; } @@ -57,13 +56,22 @@ bool lockFile(int fd, LockType lockType, bool wait) checkInterrupt(); if (errno == EWOULDBLOCK) return false; if (errno != EINTR) - throw SysError("acquiring/releasing lock"); + throw SysError("acquiring lock"); } } return true; } +void unlockFile(int fd) +{ + while (flock(fd, LOCK_UN) != 0) { + if (errno != EINTR) { + throw SysError("releasing lock"); + } + } +} + PathLocks::PathLocks() : deletePaths(false) diff --git a/lix/libstore/pathlocks.hh b/lix/libstore/pathlocks.hh index 3f46c873a..3309cd687 100644 --- a/lix/libstore/pathlocks.hh +++ b/lix/libstore/pathlocks.hh @@ -18,9 +18,10 @@ AutoCloseFD openLockFile(const Path & path, bool create); */ void deleteLockFile(const Path & path, int fd); -enum LockType { ltRead, ltWrite, ltNone }; +enum LockType { ltRead, ltWrite }; bool lockFile(int fd, LockType lockType, bool wait); +void unlockFile(int fd); class PathLocks { @@ -52,7 +53,7 @@ struct FdLock { try { if (acquired) - lockFile(fd, ltNone, false); + unlockFile(fd); } catch (SysError &) { ignoreExceptionInDestructor(); }