summaryrefslogtreecommitdiff
path: root/cmdline/apt-mark.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2014-11-18 13:41:18 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2014-11-19 18:50:05 +0100
commit1d838084dc775c0a4184edb4f3b9138903ac27fb (patch)
tree0a85e1cf02224ffe4d4fdd120b31f80e64b72a32 /cmdline/apt-mark.cc
parentb8ef7ef414600109b931fc8eebb1dfafdfe390cd (diff)
use dpkg --merge-avail only if needed in apt-mark
Only "recent" versions of dpkg support stdin for merge instead of a file, so as a quick fix we delay calling it until we really need it which fixes most of the problem already. Checking for a specific dpkg version here is deemed too much work, just like using a temporary file here and depends a too high requirement for this minor usecase. After all, it didn't work at all before, so we break nobody here and can fix it if someone complains (with a patch).
Diffstat (limited to 'cmdline/apt-mark.cc')
-rw-r--r--cmdline/apt-mark.cc100
1 files changed, 55 insertions, 45 deletions
diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc
index 860982f9e..8974397c9 100644
--- a/cmdline/apt-mark.cc
+++ b/cmdline/apt-mark.cc
@@ -274,65 +274,75 @@ static bool DoHold(CommandLine &CmdL)
return true;
}
- Args.erase(Args.begin() + BaseArgs, Args.end());
- Args.push_back("--merge-avail");
- Args.push_back("-");
- Args.push_back(NULL);
-
- int external[2] = {-1, -1};
- if (pipe(external) != 0)
- return _error->WarningE("DoHold", "Can't create IPC pipe for dpkg --merge-avail");
-
- pid_t dpkgMergeAvail = ExecFork();
- if (dpkgMergeAvail == 0)
- {
- close(external[1]);
- std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
- if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0 && chdir("/") != 0)
- _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --merge-avail", chrootDir.c_str());
- dup2(external[0], STDIN_FILENO);
- int const nullfd = open("/dev/null", O_RDONLY);
- dup2(nullfd, STDOUT_FILENO);
- execvp(Args[0], (char**) &Args[0]);
- _error->WarningE("dpkgGo", "Can't get dpkg --merge-avail running!");
- _exit(2);
- }
-
- FILE* dpkg = fdopen(external[1], "w");
+ APT::PackageList keepoffset;
for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
{
if (Pkg->CurrentVer != 0)
continue;
- char const * Arch;
- if (Pkg->VersionList != 0)
- Arch = Pkg.VersionList().Arch();
- else
- Arch = Pkg.Arch();
- fprintf(dpkg, "Package: %s\nVersion: 0~\nArchitecture: %s\nMaintainer: Dummy Example <dummy@example.org>\n"
- "Description: dummy package record\n A record is needed to put a package on hold, so here it is.\n\n", Pkg.Name(), Arch);
+ keepoffset.insert(Pkg);
}
- fclose(dpkg);
- if (dpkgMergeAvail > 0)
+ if (keepoffset.empty() == false)
{
- int Status = 0;
- while (waitpid(dpkgMergeAvail, &Status, 0) != dpkgMergeAvail)
+ Args.erase(Args.begin() + BaseArgs, Args.end());
+ Args.push_back("--merge-avail");
+ // FIXME: supported only since 1.17.7 in dpkg
+ Args.push_back("-");
+ Args.push_back(NULL);
+
+ int external[2] = {-1, -1};
+ if (pipe(external) != 0)
+ return _error->WarningE("DoHold", "Can't create IPC pipe for dpkg --merge-avail");
+
+ pid_t dpkgMergeAvail = ExecFork();
+ if (dpkgMergeAvail == 0)
{
- if (errno == EINTR)
- continue;
- _error->WarningE("dpkgGo", _("Waited for %s but it wasn't there"), "dpkg --merge-avail");
- break;
+ close(external[1]);
+ std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
+ if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0 && chdir("/") != 0)
+ _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --merge-avail", chrootDir.c_str());
+ dup2(external[0], STDIN_FILENO);
+ int const nullfd = open("/dev/null", O_RDONLY);
+ dup2(nullfd, STDOUT_FILENO);
+ execvp(Args[0], (char**) &Args[0]);
+ _error->WarningE("dpkgGo", "Can't get dpkg --merge-avail running!");
+ _exit(2);
+ }
+
+ FILE* dpkg = fdopen(external[1], "w");
+ for (APT::PackageList::iterator Pkg = keepoffset.begin(); Pkg != keepoffset.end(); ++Pkg)
+ {
+ char const * Arch;
+ if (Pkg->VersionList != 0)
+ Arch = Pkg.VersionList().Arch();
+ else
+ Arch = Pkg.Arch();
+ fprintf(dpkg, "Package: %s\nVersion: 0~\nArchitecture: %s\nMaintainer: Dummy Example <dummy@example.org>\n"
+ "Description: dummy package record\n A record is needed to put a package on hold, so here it is.\n\n", Pkg.Name(), Arch);
+ }
+ fclose(dpkg);
+ keepoffset.clear();
+
+ if (dpkgMergeAvail > 0)
+ {
+ int Status = 0;
+ while (waitpid(dpkgMergeAvail, &Status, 0) != dpkgMergeAvail)
+ {
+ if (errno == EINTR)
+ continue;
+ _error->WarningE("dpkgGo", _("Waited for %s but it wasn't there"), "dpkg --merge-avail");
+ break;
+ }
+ if (WIFEXITED(Status) == false || WEXITSTATUS(Status) != 0)
+ return _error->Error(_("Executing dpkg failed. Are you root?"));
}
- if (WIFEXITED(Status) == false || WEXITSTATUS(Status) != 0)
- return _error->Error(_("Executing dpkg failed. Are you root?"));
}
Args.erase(Args.begin() + BaseArgs, Args.end());
Args.push_back("--set-selections");
Args.push_back(NULL);
- external[0] = -1;
- external[1] = -1;
+ int external[2] = {-1, -1};
if (pipe(external) != 0)
return _error->WarningE("DoHold", "Can't create IPC pipe for dpkg --set-selections");
@@ -349,7 +359,7 @@ static bool DoHold(CommandLine &CmdL)
_exit(2);
}
- dpkg = fdopen(external[1], "w");
+ FILE* dpkg = fdopen(external[1], "w");
for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
{
if (dpkgMultiArch == false)