diff options
author | Julian Andres Klode <jak@debian.org> | 2017-01-29 13:05:18 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2018-08-07 15:07:52 +0200 |
commit | c2c8b4787b0882234ba2772ec7513afbf97b563a (patch) | |
tree | f6c0634c45d174c00192356c49a3fd7fe583e396 /apt-pkg/deb/dpkgpm.cc | |
parent | 91671efc7f63b3e2ff2a573d86ac3225e9b5f9cd (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]
Diffstat (limited to 'apt-pkg/deb/dpkgpm.cc')
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c6900ec77..790019b98 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -2010,6 +2010,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) else setenv("DPKG_COLORS", "never", 0); + if (dynamic_cast<debSystem*>(_system) != nullptr + && dynamic_cast<debSystem*>(_system)->IsLocked() == true) { + setenv("DPKG_FRONTEND_LOCKED", "true", 1); + } execvp(Args[0], (char**) &Args[0]); cerr << "Could not exec dpkg!" << endl; _exit(100); |