diff --git a/lix/legacy/build-remote.cc b/lix/legacy/build-remote.cc index b75d053f7..3d0c041b9 100644 --- a/lix/legacy/build-remote.cc +++ b/lix/legacy/build-remote.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -413,8 +414,12 @@ static int main_build_remote(AsyncIoRoot & aio, std::string programName, Strings { Activity act(*logger, lvlTalkative, actUnknown, fmt("waiting for the upload lock to '%s'", storeUri)); - if (!unsafeLockFileSingleThreaded(uploadLock.get(), ltWrite, std::chrono::minutes(15))) + auto result = aio.blockOn( + AIO().timeoutAfter(15 * kj::MINUTES, lockFileAsync(uploadLock.get(), ltWrite)) + ); + if (!result) { printError("somebody is hogging the upload lock for '%s', continuing..."); + } } auto substitute = settings.buildersUseSubstitutes ? Substitute : NoSubstitute; diff --git a/lix/libstore/pathlocks.cc b/lix/libstore/pathlocks.cc index 61b140a56..b56dd929a 100644 --- a/lix/libstore/pathlocks.cc +++ b/lix/libstore/pathlocks.cc @@ -87,28 +87,6 @@ try { return {result::current_exception()}; } -bool unsafeLockFileSingleThreaded(int fd, LockType lockType, std::chrono::seconds timeout) -{ - int type = convertLockType(lockType); - - auto old = signal(SIGALRM, [](int) {}); - alarm(timeout.count()); - KJ_DEFER({ - alarm(0); - signal(SIGALRM, old); - }); - - while (flock(fd, type) != 0) { - checkInterrupt(); - if (errno != EINTR) - throw SysError("acquiring lock"); - else - return false; - } - - return true; -} - bool tryLockFile(int fd, LockType lockType) { int type = convertLockType(lockType); diff --git a/lix/libstore/pathlocks.hh b/lix/libstore/pathlocks.hh index 375c45367..59cbb2743 100644 --- a/lix/libstore/pathlocks.hh +++ b/lix/libstore/pathlocks.hh @@ -22,13 +22,6 @@ enum LockType { ltRead, ltWrite }; void lockFile(int fd, LockType lockType, NeverAsync = {}); kj::Promise> lockFileAsync(int fd, LockType lockType); -/** - * Same as `lockFile`, but with a timeout. This timeout uses the POSIX `alarm` - * facility and a `SIGALRM` handler. Using this function from multiple threads - * in the same process is not safe: all `SIGALRM` handlers set previously will - * be overwritten while this function is executing and are restored on return. - */ -bool unsafeLockFileSingleThreaded(int fd, LockType lockType, std::chrono::seconds timeout); bool tryLockFile(int fd, LockType lockType); void unlockFile(int fd);