diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/deb/debsystem.cc | 55 | ||||
-rw-r--r-- | apt-pkg/deb/debsystem.h | 4 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 5 | ||||
-rw-r--r-- | apt-pkg/pkgsystem.cc | 25 | ||||
-rw-r--r-- | apt-pkg/pkgsystem.h | 12 |
5 files changed, 93 insertions, 8 deletions
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index 7118b534b..c087d6914 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -46,10 +46,11 @@ debSystem debSys; class APT_HIDDEN debSystemPrivate { public: - debSystemPrivate() : LockFD(-1), LockCount(0), StatusFile(0) + debSystemPrivate() : FrontendLockFD(-1), LockFD(-1), LockCount(0), StatusFile(0) { } // For locking support + int FrontendLockFD; int LockFD; unsigned LockCount; @@ -86,22 +87,30 @@ bool debSystem::Lock() } // Create the lockfile - string AdminDir = flNotFile(_config->Find("Dir::State::status")); - d->LockFD = GetLock(AdminDir + "lock"); - if (d->LockFD == -1) + string AdminDir = flNotFile(_config->FindFile("Dir::State::status")); + string FrontendLockFile = AdminDir + "lock-frontend"; + d->FrontendLockFD = GetLock(FrontendLockFile); + if (d->FrontendLockFD == -1) { if (errno == EACCES || errno == EAGAIN) - return _error->Error(_("Unable to lock the administration directory (%s), " - "is another process using it?"),AdminDir.c_str()); + return _error->Error(_("Unable to acquire the dpkg frontend lock (%s), " + "is another process using it?"),FrontendLockFile.c_str()); else - return _error->Error(_("Unable to lock the administration directory (%s), " - "are you root?"),AdminDir.c_str()); + return _error->Error(_("Unable to acquire the dpkg frontend lock (%s), " + "are you root?"),FrontendLockFile.c_str()); + } + if (LockInner() == false) + { + close(d->FrontendLockFD); + return false; } // See if we need to abort with a dirty journal if (CheckUpdates() == true) { close(d->LockFD); + close(d->FrontendLockFD); + d->FrontendLockFD = -1; d->LockFD = -1; const char *cmd; if (getenv("SUDO_USER") != NULL) @@ -118,6 +127,21 @@ bool debSystem::Lock() return true; } + +bool debSystem::LockInner() { + string AdminDir = flNotFile(_config->FindFile("Dir::State::status")); + d->LockFD = GetLock(AdminDir + "lock"); + if (d->LockFD == -1) + { + if (errno == EACCES || errno == EAGAIN) + return _error->Error(_("Unable to lock the administration directory (%s), " + "is another process using it?"),AdminDir.c_str()); + else + return _error->Error(_("Unable to lock the administration directory (%s), " + "are you root?"),AdminDir.c_str()); + } + return true; +} /*}}}*/ // System::UnLock - Drop a lock /*{{{*/ // --------------------------------------------------------------------- @@ -131,12 +155,27 @@ bool debSystem::UnLock(bool NoErrors) return _error->Error(_("Not locked")); if (--d->LockCount == 0) { + close(d->FrontendLockFD); close(d->LockFD); d->LockCount = 0; } return true; } +bool debSystem::UnLockInner(bool NoErrors) { + (void) NoErrors; + close(d->LockFD); + return true; +} + /*}}}*/ +// System::IsLocked - Check if system is locked /*{{{*/ +// --------------------------------------------------------------------- +/* This checks if the frontend lock is hold. The inner lock might be + * released. */ +bool debSystem::IsLocked() +{ + return d->LockCount > 0; +} /*}}}*/ // System::CheckUpdates - Check if the updates dir is dirty /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index 5185c92d8..2eb22a40f 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -52,6 +52,10 @@ class debSystem : public pkgSystem APT_HIDDEN static pid_t ExecDpkg(std::vector<std::string> const &sArgs, int * const inputFd, int * const outputFd, bool const DiscardOutput); APT_HIDDEN static bool SupportsMultiArch(); APT_HIDDEN static std::vector<std::string> SupportedArchitectures(); + + APT_HIDDEN bool LockInner(); + APT_HIDDEN bool UnLockInner(bool NoErrors=false); + APT_HIDDEN bool IsLocked(); }; extern debSystem debSys; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 533d9b367..37452f3d3 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1521,6 +1521,11 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) _exit(100); } + 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); 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() {} diff --git a/apt-pkg/pkgsystem.h b/apt-pkg/pkgsystem.h index 55bdeec70..8c7c300fb 100644 --- a/apt-pkg/pkgsystem.h +++ b/apt-pkg/pkgsystem.h @@ -116,6 +116,18 @@ class pkgSystem pkgSystem(char const * const Label, pkgVersioningSystem * const VS); virtual ~pkgSystem(); + + + /* companions to Lock()/UnLock + * + * These functions can be called prior to calling dpkg to release an inner + * lock without releasing the overall outer lock, so that dpkg can run + * correctly but no other APT instance can acquire the system lock. + */ + bool LockInner(); + bool UnLockInner(bool NoErrors = false); + /// checks if the system is currently locked + bool IsLocked(); private: void * const d; }; |