From f6ffe501d432d1299808ae307936877cf2c5f8ce Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 15 Mar 2014 17:59:47 +0100 Subject: Fix handling of autoclosing for compressed files (Closes: #741685) AutoClose is both an argument in OpenDescriptor() and an enum. In commit 84baaae93badc2da7c1f4f356456762895cef278 code using the AutoClose parameter was moved to OpenDescriptorInternal(). In that function, AutoClose meant the enum value, so the check was always false. --- apt-pkg/contrib/fileutl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1eabf37f4..ba79720d8 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1191,7 +1191,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C d->openmode = Mode; d->compressor = compressor; #if defined HAVE_ZLIB || defined HAVE_BZ2 || defined HAVE_LZMA - if (AutoClose == false && compress_open != NULL) + if ((Flags & AutoClose) != AutoClose && compress_open != NULL) { // Need to duplicate fd here or gz/bz2 close for cleanup will close the fd as well int const internFd = dup(iFd); -- cgit v1.2.3 From c4b113e650dbdbb4c5c9c6f36437c94db6b214d9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 21 Mar 2014 11:04:26 +0100 Subject: continue reading in xz even if it outputs nothing It can happen that content in our buffer is not enough to produce a meaningful output in which case no output is created by liblzma, but still reports that everything is okay and we should go on. The code assumes it has reached the end through if it encounters a null read, so this commit makes it so that it looks like this read was interrupted just like the lowlevel read() on uncompressed files could. It subsequently fixes the issue with that as well as until now our loop would still break even if we wanted it to continue on. (This bug triggers our usual "Hash sum mismatch" error) Reported-By: Stefan Lippers-Hollmann --- apt-pkg/contrib/fileutl.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index ba79720d8..69406a9bf 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1430,7 +1430,15 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) errno = 0; } else + { Res = Size - d->lzma->stream.avail_out; + if (Res == 0) + { + // lzma run was okay, but produced no output… + Res = -1; + errno = EINTR; + } + } } #endif else @@ -1439,7 +1447,12 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) if (Res < 0) { if (errno == EINTR) + { + // trick the while-loop into running again + Res = 1; + errno = 0; continue; + } if (false) /* dummy so that the rest can be 'else if's */; #ifdef HAVE_ZLIB -- cgit v1.2.3 From 63ff42089863cda53aee240ea0124106e8b4d983 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 21 Mar 2014 15:54:15 +0100 Subject: enable fvisibility=hidden for our private library While it is a huge undertaking to enable it for our public libraries as basically everything we exported so far could be seen as public interface our private library is new and under our full control, so we can do whatever we like with it. The benefits are not that big in return of course, but it reduces the size a bit, so thats great nontheless. Git-Dch: ignore --- apt-pkg/contrib/macros.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index d97053553..2d6448e5e 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -94,8 +94,12 @@ #if APT_GCC_VERSION >= 0x0400 #define APT_SENTINEL __attribute__((sentinel)) + #define APT_PUBLIC __attribute__ ((visibility ("default"))) + #define APT_HIDDEN __attribute__ ((visibility ("hidden"))) #else #define APT_SENTINEL + #define APT_PUBLIC + #define APT_HIDDEN #endif // cold functions are unlikely() to be called -- cgit v1.2.3 From ce62f1def6565375ce9c56eb1237ccdc0ca138ba Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 21 Mar 2014 16:26:01 +0100 Subject: mark optional (private) symbols as hidden This methods should not be used by anyone expect the library itself as they are helpers for the specific class and therefore perfect candidates for hidding. Git-Dch: Ignore --- apt-pkg/acquire-method.h | 4 +++- apt-pkg/cdrom.h | 4 +++- apt-pkg/contrib/fileutl.h | 6 +++--- apt-pkg/deb/deblistparser.h | 3 ++- apt-pkg/edsp.h | 11 ++++++----- apt-pkg/pkgcachegen.h | 18 +++++++++--------- apt-pkg/tagfile.h | 8 +++++--- 7 files changed, 31 insertions(+), 23 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index f0f2a537a..221ccf273 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -20,6 +20,8 @@ #ifndef PKGLIB_ACQUIRE_METHOD_H #define PKGLIB_ACQUIRE_METHOD_H +#include + #include #include @@ -107,7 +109,7 @@ class pkgAcqMethod virtual ~pkgAcqMethod() {}; private: - void Dequeue(); + APT_HIDDEN void Dequeue(); }; /** @} */ diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h index 0ed4a6a73..0f2c2cd02 100644 --- a/apt-pkg/cdrom.h +++ b/apt-pkg/cdrom.h @@ -1,6 +1,8 @@ #ifndef PKGLIB_CDROM_H #define PKGLIB_CDROM_H +#include + #include #include @@ -73,7 +75,7 @@ class pkgCdrom /*{{{*/ bool Add(pkgCdromStatus *log); private: - bool MountAndIdentCDROM(Configuration &Database, std::string &CDROM, + APT_HIDDEN bool MountAndIdentCDROM(Configuration &Database, std::string &CDROM, std::string &ident, pkgCdromStatus * const log, bool const interactive); }; /*}}}*/ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 278a25742..f25ed3622 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -150,11 +150,11 @@ class FileFd private: FileFdPrivate* d; - bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor); + APT_HIDDEN bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor); // private helpers to set Fail flag and call _error->Error - bool FileFdErrno(const char* Function, const char* Description,...) APT_PRINTF(3) APT_COLD; - bool FileFdError(const char* Description,...) APT_PRINTF(2) APT_COLD; + APT_HIDDEN bool FileFdErrno(const char* Function, const char* Description,...) APT_PRINTF(3) APT_COLD; + APT_HIDDEN bool FileFdError(const char* Description,...) APT_PRINTF(2) APT_COLD; }; bool RunScripts(const char *Cnf); diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 286244cc9..baace79fe 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -102,7 +103,7 @@ class debListParser : public pkgCacheGenerator::ListParser virtual ~debListParser() {}; private: - unsigned char ParseMultiArch(bool const showErrors); + APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors); }; #endif diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index ae20ed7db..f3092d3c6 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -32,15 +33,15 @@ class EDSP /*{{{*/ static const char * const PrioMap[]; static const char * const DepMap[]; - bool static ReadLine(int const input, std::string &line); - bool static StringToBool(char const *answer, bool const defValue); + APT_HIDDEN bool static ReadLine(int const input, std::string &line); + APT_HIDDEN bool static StringToBool(char const *answer, bool const defValue); - void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output, + APT_HIDDEN void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver); - void static WriteScenarioDependency(FILE* output, + APT_HIDDEN void static WriteScenarioDependency(FILE* output, pkgCache::VerIterator const &Ver); - void static WriteScenarioLimitedDependency(FILE* output, + APT_HIDDEN void static WriteScenarioLimitedDependency(FILE* output, pkgCache::VerIterator const &Ver, APT::PackageSet const &pkgset); public: diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 5994dab9f..1e1a71026 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -38,10 +38,10 @@ class pkgCacheGenerator /*{{{*/ private: pkgCache::StringItem *UniqHash[26]; - map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; - map_ptrloc WriteStringInMap(const char *String); - map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len); - map_ptrloc AllocateInMap(const unsigned long &size); + APT_HIDDEN map_ptrloc WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; + APT_HIDDEN map_ptrloc WriteStringInMap(const char *String); + APT_HIDDEN map_ptrloc WriteStringInMap(const char *String, const unsigned long &Len); + APT_HIDDEN map_ptrloc AllocateInMap(const unsigned long &size); public: @@ -117,14 +117,14 @@ class pkgCacheGenerator /*{{{*/ ~pkgCacheGenerator(); private: - bool MergeListGroup(ListParser &List, std::string const &GrpName); - bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); - bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, + APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); + APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); + APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, std::string const &Version, pkgCache::VerIterator* &OutVer); - bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, + APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, pkgCache::VerIterator &V); - bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); + APT_HIDDEN bool AddImplicitDepends(pkgCache::VerIterator &V, pkgCache::PkgIterator &D); }; /*}}}*/ // This is the abstract package list parser class. /*{{{*/ diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 2f600d397..d5b62e76d 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -20,6 +20,8 @@ #ifndef PKGLIB_TAGFILE_H #define PKGLIB_TAGFILE_H +#include + #include #include @@ -93,9 +95,9 @@ class pkgTagFile { pkgTagFilePrivate *d; - bool Fill(); - bool Resize(); - bool Resize(unsigned long long const newSize); + APT_HIDDEN bool Fill(); + APT_HIDDEN bool Resize(); + APT_HIDDEN bool Resize(unsigned long long const newSize); public: -- cgit v1.2.3 From d151adbf2cc4d23c240c6c4fcfbfda439a98c36f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 22 Mar 2014 21:35:57 +0100 Subject: ensure proper teardown in dpkg error cases We have to properly close our pseudo terminals even in error cases before we call post-invoke scripts. This is done now by breaking from the dpkg calling loop instead of copying the handling, which did it in the wrong order before. This also ensures that our state file is written in error cases to record autobit and co as this was forgotten before. Closes: 738969 --- apt-pkg/deb/dpkgpm.cc | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 9fee7c923..5a5fff13b 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1530,28 +1530,18 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress) // here but keep the loop going and just report it as a error // for later bool const stopOnError = _config->FindB("Dpkg::StopOnError",true); - - if(stopOnError) - RunScripts("DPkg::Post-Invoke"); - if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) + if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) strprintf(d->dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]); else if (WIFEXITED(Status) != 0) strprintf(d->dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status)); - else + else strprintf(d->dpkg_error, "Sub-process %s exited unexpectedly",Args[0]); + _error->Error("%s", d->dpkg_error.c_str()); - if(d->dpkg_error.size() > 0) - _error->Error("%s", d->dpkg_error.c_str()); - - if(stopOnError) - { - CloseLog(); - StopPtyMagic(); - d->progress->Stop(); - return false; - } - } + if(stopOnError) + break; + } } // dpkg is done at this point d->progress->Stop(); @@ -1582,7 +1572,7 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress) } Cache.writeStateFile(NULL); - return true; + return d->dpkg_error.empty(); } void SigINT(int /*sig*/) { -- cgit v1.2.3 From be7ce6f1d067fa62b01685e48094f3f73c95189f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 11 Mar 2014 15:32:40 +0100 Subject: do IsInstallOk call in MarkInstall unconditionally Hooked checks could be influenced by AutoInst as a lot can happen between a call without and one with this bit set. The real cache-hit check is above this call already. Individual hooked checks can then inspect the state if they want to cache. Calling them multiple times shouldn't be a problem either way. --- apt-pkg/depcache.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index e2c412757..5fa88a5d2 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1059,10 +1059,9 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, return true; } - // check if we are allowed to install the package (if we haven't already) - if (P.Mode != ModeInstall || P.InstallVer != P.CandidateVer) - if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false) - return false; + // check if we are allowed to install the package + if (IsInstallOk(Pkg,AutoInst,Depth,FromUser) == false) + return false; ActionGroup group(*this); P.iFlags &= ~AutoKept; @@ -1308,6 +1307,11 @@ bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, if (FromUser == true) // as always: user is always right return true; + // if we have checked before and it was okay, it will still be okay + if (PkgState[Pkg->ID].Mode == ModeInstall && + PkgState[Pkg->ID].InstallVer == PkgState[Pkg->ID].CandidateVer) + return true; + // ignore packages with none-M-A:same candidates VerIterator const CandVer = PkgState[Pkg->ID].CandidateVerIter(*this); if (unlikely(CandVer.end() == true) || CandVer == Pkg.CurrentVer() || -- cgit v1.2.3 From 21b3eac8f9ab8e12b43fa8998a5aa5465f29adc5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 11 Mar 2014 10:31:44 +0100 Subject: discard candidates via IsInstallOk to allow override In commit 446551c8 I changed MarkInstall to discard the candidate if the candidate can't satisfy the dependency. This breaks interactive solvers like aptitude which can change the candidate on-the-fly later. In commit df77d8a5 I introduced this 'early' loop-breaking to begin with which can't be that helpful for interactive solvers as well, but makes perfect sense for non-interactives to stop them from exploring trees which can't be satisfied, but it isn't perfect as ideally we would check this before auto-installing the first dependency. This commit therefore moves the loop into its own IsInstallOk hook so that frontends can override this check if they want to and in exchange removes the loop-breaking from MarkInstall itself and does it before any dependency is installed. Closes: 740750 --- apt-pkg/depcache.cc | 78 +++++++++++++++++++++++++++++++++++++++-------------- apt-pkg/depcache.h | 2 ++ 2 files changed, 60 insertions(+), 20 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 5fa88a5d2..19a6e0d7e 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1122,32 +1122,22 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, continue; /* Check if this dep should be consider for install. If it is a user - defined important dep and we are installed a new package then + defined important dep and we are installed a new package then it will be installed. Otherwise we only check for important - deps that have changed from the installed version - */ + deps that have changed from the installed version */ if (IsImportantDep(Start) == false) continue; - /* If we are in an or group locate the first or that can - succeed. We have already cached this.. */ + /* If we are in an or group locate the first or that can + succeed. We have already cached this… */ for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; --Ors) ++Start; + + /* unsatisfiable dependency: IsInstallOkDependenciesSatisfiableByCandidates + would have prevented us to get here if not overridden, so just skip + over the problem here as the frontend will know what it is doing */ if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer && Start.IsNegative() == false) - { - if(DebugAutoInstall == true) - std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl; - if (Start.IsCritical() == false) - continue; - // if the dependency was critical, we have absolutely no chance to install it, - // so if it wasn't installed remove it again. If it was, discard the candidate - // as the problemresolver will trip over it otherwise trying to install it (#735967) - if (Pkg->CurrentVer == 0) - MarkDelete(Pkg,false,Depth + 1, false); - else - SetCandidateVersion(Pkg.CurrentVer()); - return false; - } + continue; /* Check if any ImportantDep() (but not Critical) were added * since we installed the package. Also check for deps that @@ -1299,7 +1289,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, bool pkgDepCache::IsInstallOk(PkgIterator const &Pkg,bool AutoInst, unsigned long Depth, bool FromUser) { - return IsInstallOkMultiArchSameVersionSynced(Pkg,AutoInst, Depth, FromUser); + return IsInstallOkMultiArchSameVersionSynced(Pkg,AutoInst, Depth, FromUser) && + IsInstallOkDependenciesSatisfiableByCandidates(Pkg,AutoInst, Depth, FromUser); } bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, bool const /*AutoInst*/, unsigned long const Depth, bool const FromUser) @@ -1342,6 +1333,53 @@ bool pkgDepCache::IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, return false; } + return true; +} +bool pkgDepCache::IsInstallOkDependenciesSatisfiableByCandidates(PkgIterator const &Pkg, + bool const AutoInst, unsigned long const Depth, bool const /*FromUser*/) +{ + if (AutoInst == false) + return true; + + VerIterator const CandVer = PkgState[Pkg->ID].CandidateVerIter(*this); + if (unlikely(CandVer.end() == true) || CandVer == Pkg.CurrentVer()) + return true; + + for (DepIterator Dep = CandVer.DependsList(); Dep.end() != true;) + { + // Grok or groups + DepIterator Start = Dep; + bool Result = true; + unsigned Ors = 0; + for (bool LastOR = true; Dep.end() == false && LastOR == true; ++Dep, ++Ors) + { + LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or; + + if ((DepState[Dep->ID] & DepInstall) == DepInstall) + Result = false; + } + + if (Start.IsCritical() == false || Start.IsNegative() == true || Result == false) + continue; + + /* If we are in an or group locate the first or that can succeed. + We have already cached this… */ + for (; Ors > 1 && (DepState[Start->ID] & DepCVer) != DepCVer; --Ors) + ++Start; + + if (Ors == 1 && (DepState[Start->ID] &DepCVer) != DepCVer) + { + if (DebugAutoInstall == true) + std::clog << OutputInDepth(Depth) << Start << " can't be satisfied!" << std::endl; + + // the dependency is critical, but can't be installed, so discard the candidate + // as the problemresolver will trip over it otherwise trying to install it (#735967) + if (Pkg->CurrentVer != 0) + SetCandidateVersion(Pkg.CurrentVer()); + return false; + } + } + return true; } /*}}}*/ diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index bde648c65..bec651279 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -506,6 +506,8 @@ class pkgDepCache : protected pkgCache::Namespace // methods call by IsInstallOk bool IsInstallOkMultiArchSameVersionSynced(PkgIterator const &Pkg, bool const AutoInst, unsigned long const Depth, bool const FromUser); + bool IsInstallOkDependenciesSatisfiableByCandidates(PkgIterator const &Pkg, + bool const AutoInst, unsigned long const Depth, bool const FromUser); // methods call by IsDeleteOk bool IsDeleteOkProtectInstallRequests(PkgIterator const &Pkg, -- cgit v1.2.3