summaryrefslogtreecommitdiff
path: root/apt-pkg/pkgsystem.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2017-01-29 13:05:18 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2018-09-28 13:25:32 +0200
commit8a9a2147bc4346c7e3da8a08719b8f2686d65887 (patch)
treef886d60b1e6e1c171d0274d9f9e333e20c53d3ec /apt-pkg/pkgsystem.cc
parent8e28398f3bc9cc9e8c5a038ef26823fc41dc5910 (diff)
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] (cherry picked from commit c2c8b4787b0882234ba2772ec7513afbf97b563a) LP: #1781169 (cherry picked from commit 6c0c94ed32b8e679b14b0f89b51c1c336dc0ab9c)
Diffstat (limited to 'apt-pkg/pkgsystem.cc')
-rw-r--r--apt-pkg/pkgsystem.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/apt-pkg/pkgsystem.cc b/apt-pkg/pkgsystem.cc
index 530150221..99d104310 100644
--- a/apt-pkg/pkgsystem.cc
+++ b/apt-pkg/pkgsystem.cc
@@ -13,6 +13,7 @@
#include<config.h>
#include <apt-pkg/debsystem.h>
+#include <apt-pkg/error.h>
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/macros.h>
@@ -64,4 +65,28 @@ std::vector<std::string> pkgSystem::ArchitecturesSupported() const /*{{{*/
}
/*}}}*/
+bool pkgSystem::LockInner() /*{{{*/
+{
+ debSystem * const deb = dynamic_cast<debSystem *>(this);
+ if (deb != NULL)
+ return deb->LockInner();
+ return _error->Error("LockInner is not implemented");
+}
+ /*}}}*/
+bool pkgSystem::UnLockInner(bool NoErrors) /*{{{*/
+{
+ debSystem * const deb = dynamic_cast<debSystem *>(this);
+ if (deb != NULL)
+ return deb->UnLockInner(NoErrors);
+ return _error->Error("UnLockInner is not implemented");
+}
+ /*}}}*/
+bool pkgSystem::IsLocked() /*{{{*/
+{
+ debSystem * const deb = dynamic_cast<debSystem *>(this);
+ if (deb != NULL)
+ return deb->IsLocked();
+ return true;
+}
+ /*}}}*/
pkgSystem::~pkgSystem() {}