From 86fc2ca8909eb686e2ad751acb0f0eaf706d9d5e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 13 Jan 2012 17:30:17 +0100 Subject: * apt-pkg/deb/dpkgpm.cc: - check if dpkg supports multiarch with --assert-multi-arch and if it does be always explicit about the architecture --- apt-pkg/deb/dpkgpm.cc | 73 ++++++++++++++++++++-------- debian/changelog | 5 +- test/integration/test-dpkg-assert-multi-arch | 53 ++++++++++++++++++++ 3 files changed, 109 insertions(+), 22 deletions(-) create mode 100755 test/integration/test-dpkg-assert-multi-arch diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 7c0ed5639..4dc0baa50 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -108,7 +108,7 @@ ionice(int PID) { if (!FileExists("/usr/bin/ionice")) return false; - pid_t Process = ExecFork(); + pid_t Process = ExecFork(); if (Process == 0) { char buf[32]; @@ -829,6 +829,40 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds, */ bool pkgDPkgPM::Go(int OutStatusFd) { + // Generate the base argument list for dpkg + std::vector Args; + unsigned long StartSize = 0; + string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + Args.push_back(Tmp.c_str()); + StartSize += Tmp.length(); + + // Stick in any custom dpkg options + Configuration::Item const *Opts = _config->Tree("DPkg::Options"); + if (Opts != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + Args.push_back(Opts->Value.c_str()); + StartSize += Opts->Value.length(); + } + } + + size_t const BaseArgs = Args.size(); + // we need to detect if we can qualify packages with the architecture or not + Args.push_back("--assert-multi-arch"); + Args.push_back(NULL); + + pid_t dpkgAssertMultiArch = ExecFork(); + if (dpkgAssertMultiArch == 0) + { + execv(Args[0], (char**) &Args[0]); + _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); + _exit(2); + } + fd_set rfds; struct timespec tv; sigset_t sigmask; @@ -905,27 +939,20 @@ bool pkgDPkgPM::Go(int OutStatusFd) // create log OpenLog(); - // Generate the base argument list for dpkg - std::vector Args; - unsigned long StartSize = 0; - string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); - Args.push_back(Tmp.c_str()); - StartSize += Tmp.length(); - - // Stick in any custom dpkg options - Configuration::Item const *Opts = _config->Tree("DPkg::Options"); - if (Opts != 0) + bool dpkgMultiArch = false; + if (dpkgAssertMultiArch > 0) { - Opts = Opts->Child; - for (; Opts != 0; Opts = Opts->Next) + int Status = 0; + while (waitpid(dpkgAssertMultiArch, &Status, 0) != dpkgAssertMultiArch) { - if (Opts->Value.empty() == true) + if (errno == EINTR) continue; - Args.push_back(Opts->Value.c_str()); - StartSize += Opts->Value.length(); + _error->WarningE("dpkgGo", _("Waited for %s but it wasn't there"), "dpkg --assert-multi-arch"); + break; } + if (WIFEXITED(Status) == true && WEXITSTATUS(Status) == 0) + dpkgMultiArch = true; } - size_t const BaseArgs = Args.size(); // this loop is runs once per operation for (vector::const_iterator I = List.begin(); I != List.end();) @@ -965,14 +992,17 @@ bool pkgDPkgPM::Go(int OutStatusFd) if (J - I > (signed)MaxArgs) { J = I + MaxArgs; - Args.reserve(MaxArgs + 10); + unsigned long const size = MaxArgs + 10; + Args.reserve(size); + Packages.reserve(size); } else { - Args.reserve((J - I) + 10); + unsigned long const size = (J - I) + 10; + Args.reserve(size); + Packages.reserve(size); } - int fd[2]; pipe(fd); @@ -1047,7 +1077,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) continue; if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end()) continue; - if (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all")) + // We keep this here to allow "smooth" transitions from e.g. multiarch dpkg/ubuntu to dpkg/debian + if (dpkgMultiArch == false && (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all"))) { char const * const name = I->Pkg.Name(); ADDARG(name); diff --git a/debian/changelog b/debian/changelog index 36b3d8340..5eb4e593f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,8 +6,11 @@ apt (0.8.16~exp10) UNRELEASED; urgency=low only with real packages, not with virtual providers * apt-pkg/pkgcache.cc: - ignore implicit conflicts on providers in AllTarget, too + * apt-pkg/deb/dpkgpm.cc: + - check if dpkg supports multiarch with --assert-multi-arch + and if it does be always explicit about the architecture - -- David Kalnischkies Fri, 13 Jan 2012 12:47:33 +0100 + -- David Kalnischkies Fri, 13 Jan 2012 17:29:07 +0100 apt (0.8.16~exp9) experimental; urgency=low diff --git a/test/integration/test-dpkg-assert-multi-arch b/test/integration/test-dpkg-assert-multi-arch new file mode 100755 index 000000000..b1ec73e18 --- /dev/null +++ b/test/integration/test-dpkg-assert-multi-arch @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'amd64' 'i386' + +buildsimplenativepackage 'native-pkg' 'amd64' '1.0' 'stable' +buildsimplenativepackage 'foreign-pkg' 'i386' '0.5' 'stable' 'Multi-Arch: foreign' +buildsimplenativepackage 'same-lib' 'amd64,i386' '0.5' 'stable' 'Multi-Arch: same' + +setupaptarchive + +testqualifier() { + msgtest 'Test for correct qualifier mode' $2 + GIVEN="$(aptget install $1 -qq -o Debug::pkgDPkgPM=1 2>&1 | grep -- '--configure' | sed -e 's/^.*--configure \([^ ]*\).*$/\1/')" + test "$GIVEN" = "$2" && msgpass || msgfail +} + +# non-multiarch or "ubuntus" old multiarchified dpkg +echo 'Dir::Bin::dpkg "./dpkg-wrapper";' > rootdir/etc/apt/apt.conf.d/99dpkgwrapper +echo '#! /bin/sh +if echo "$*" | grep -q -- "--assert-multi-arch"; then + return 2; +fi +return $*' > ./dpkg-wrapper +chmod +x ./dpkg-wrapper + +testqualifier 'native-pkg' 'native-pkg' +testqualifier 'native-pkg:amd64' 'native-pkg' +testqualifier 'foreign-pkg' 'foreign-pkg:i386' +testqualifier 'foreign-pkg:i386' 'foreign-pkg:i386' +testqualifier 'same-lib' 'same-lib' +testqualifier 'same-lib:amd64' 'same-lib' +testqualifier 'same-lib:i386' 'same-lib:i386' + +# multiarch dpkg (new interface version) + +echo 'Dir::Bin::dpkg "./dpkg-wrapper";' > rootdir/etc/apt/apt.conf.d/99dpkgwrapper +echo '#! /bin/sh +if echo "$*" | grep -q -- "--assert-multi-arch"; then + return 0; +fi +return $*' > ./dpkg-wrapper + +testqualifier 'native-pkg' 'native-pkg:amd64' +testqualifier 'native-pkg:amd64' 'native-pkg:amd64' +testqualifier 'foreign-pkg' 'foreign-pkg:i386' +testqualifier 'foreign-pkg:i386' 'foreign-pkg:i386' +testqualifier 'same-lib' 'same-lib:amd64' +testqualifier 'same-lib:amd64' 'same-lib:amd64' +testqualifier 'same-lib:i386' 'same-lib:i386' -- cgit v1.2.3-70-g09d2