summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/debsystem.cc53
-rw-r--r--apt-pkg/deb/debsystem.h4
-rw-r--r--apt-pkg/deb/dpkgpm.cc4
3 files changed, 54 insertions, 7 deletions
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc
index 2bb887e75..ee42cc6a7 100644
--- a/apt-pkg/deb/debsystem.cc
+++ b/apt-pkg/deb/debsystem.cc
@@ -45,10 +45,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,21 +87,29 @@ bool debSystem::Lock()
// Create the lockfile
string AdminDir = flNotFile(_config->FindFile("Dir::State::status"));
- d->LockFD = GetLock(AdminDir + "lock");
- if (d->LockFD == -1)
+ 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)
@@ -117,6 +126,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 /*{{{*/
// ---------------------------------------------------------------------
@@ -130,12 +154,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 9fdecb42f..9de3c8b4e 100644
--- a/apt-pkg/deb/debsystem.h
+++ b/apt-pkg/deb/debsystem.h
@@ -51,6 +51,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 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);