From 60cc44d160af02c49614653c97bfa3e4e5c9601d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 15 Apr 2019 11:32:50 +0200 Subject: Prevent shutdown while running dpkg As long as we are running dpkg, keep an inhibitor that blocks us from shutting down. LP: #1820886 --- apt-pkg/deb/dpkgpm.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'apt-pkg/deb/dpkgpm.cc') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 101571782..ad5a9007e 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1448,6 +1448,21 @@ bool pkgDPkgPM::ExpandPendingCalls(std::vector &List, pkgDepCache &Cache) } bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) { + struct Inhibitor + { + int Fd = -1; + Inhibitor() + { + if (_config->FindB("DPkg::Inhibit-Shutdown", true)) + Fd = Inhibit("shutdown", "APT", "APT is installing or removing packages", "block"); + } + ~Inhibitor() + { + if (Fd > 0) + close(Fd); + } + } inhibitor; + // explicitly remove&configure everything for hookscripts and progress building // we need them only temporarily through, so keep the length and erase afterwards decltype(List)::const_iterator::difference_type explicitIdx = -- cgit v1.2.3