From c2c8b4787b0882234ba2772ec7513afbf97b563a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 29 Jan 2017 13:05:18 +0100 Subject: Add support for dpkg frontend lock The dpkg frontend lock is a lock dpkg tries to acquire except if the frontend already acquires it. This fixes a race condition in the install command where the dpkg lock is not held for a short period of time between different dpkg invocations. For this reason we also define an environment variable DPKG_FRONTEND_LOCKED for dpkg invocations so dpkg knows not to try to acquire the frontend lock because it's held by a parent process. We can set DPKG_FRONTEND_LOCKED only if the frontend lock really is held; that is, if our lock count is greater than 0 - otherwise an apt client not using the LockInner family of functions would run dpkg without the frontend lock set, but with DPKG_FRONTEND_LOCKED set. Such a process has a weaker guarantee: Because dpkg would not lock the frontend lock either, the process is prone to the existing races, and, more importantly, so is a new style process. Closes: #869546 [fixups: fix error messages, add public IsLocked() method, and make {Un,}LockInner return an error on !debSystem] --- apt-pkg/deb/debsystem.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apt-pkg/deb/debsystem.h') diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index 7b59fc073..4503676fa 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -50,6 +50,10 @@ class debSystem : public pkgSystem APT_HIDDEN static pid_t ExecDpkg(std::vector const &sArgs, int * const inputFd, int * const outputFd, bool const DiscardOutput); APT_HIDDEN static bool SupportsMultiArch(); APT_HIDDEN static std::vector SupportedArchitectures(); + + APT_HIDDEN bool LockInner(); + APT_HIDDEN bool UnLockInner(bool NoErrors=false); + APT_HIDDEN bool IsLocked(); }; extern debSystem debSys; -- cgit v1.2.3