diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/acquire-worker.cc | 7 | ||||
-rw-r--r-- | apt-pkg/acquire.cc | 5 | ||||
-rw-r--r-- | apt-pkg/algorithms.cc | 13 | ||||
-rw-r--r-- | apt-pkg/cacheiterators.h | 10 | ||||
-rw-r--r-- | apt-pkg/cdrom.cc | 88 | ||||
-rw-r--r-- | apt-pkg/cdrom.h | 37 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 13 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.h | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 7 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.cc | 13 | ||||
-rw-r--r-- | apt-pkg/contrib/md5.cc | 13 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.cc | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/sha256.h | 1 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 28 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 2 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 2 | ||||
-rw-r--r-- | apt-pkg/deb/debsystem.cc | 12 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 83 | ||||
-rw-r--r-- | apt-pkg/indexcopy.cc | 10 | ||||
-rw-r--r-- | apt-pkg/indexrecords.cc | 6 | ||||
-rw-r--r-- | apt-pkg/makefile | 2 | ||||
-rw-r--r-- | apt-pkg/pkgcache.cc | 4 |
22 files changed, 301 insertions, 60 deletions
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index 78c68737c..4f0b52af9 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -527,10 +527,6 @@ bool pkgAcquire::Worker::OutFdReady() if (Res <= 0) return MethodFailure(); - - // Hmm.. this should never happen. - if (Res < 0) - return true; OutQueue.erase(0,Res); if (OutQueue.empty() == true) @@ -558,7 +554,8 @@ bool pkgAcquire::Worker::MethodFailure() { _error->Error("Method %s has died unexpectedly!",Access.c_str()); - ExecWait(Process,Access.c_str(),true); + // do not reap the child here to show meaningfull error to the user + ExecWait(Process,Access.c_str(),false); Process = -1; close(InFd); close(OutFd); diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 68ff393d0..74510ae21 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -24,7 +24,8 @@ #include <iostream> #include <sstream> - +#include <stdio.h> + #include <dirent.h> #include <sys/time.h> #include <errno.h> @@ -618,7 +619,7 @@ bool pkgAcquire::Queue::Startup() added other source retry to have cycle maintain a pipeline depth on its own. */ if (Cnf->Pipeline == true) - MaxPipeDepth = 1000; + MaxPipeDepth = _config->FindI("Acquire::Max-Pipeline-Depth",10); else MaxPipeDepth = 1; } diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index a30a02edb..34da745de 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -500,6 +500,7 @@ void pkgProblemResolver::MakeScores() signed short PrioEssentials = _config->FindI("pkgProblemResolver::Scores::Essentials",100); signed short PrioInstalledAndNotObsolete = _config->FindI("pkgProblemResolver::Scores::NotObsolete",1); signed short PrioDepends = _config->FindI("pkgProblemResolver::Scores::Depends",1); + signed short PrioRecommends = _config->FindI("pkgProblemResolver::Scores::Recommends",1); signed short AddProtected = _config->FindI("pkgProblemResolver::Scores::AddProtected",10000); signed short AddEssential = _config->FindI("pkgProblemResolver::Scores::AddEssential",5000); @@ -513,6 +514,7 @@ void pkgProblemResolver::MakeScores() << " Essentials => " << PrioEssentials << endl << " InstalledAndNotObsolete => " << PrioInstalledAndNotObsolete << endl << " Depends => " << PrioDepends << endl + << " Recommends => " << PrioRecommends << endl << " AddProtected => " << AddProtected << endl << " AddEssential => " << AddEssential << endl; @@ -551,8 +553,11 @@ void pkgProblemResolver::MakeScores() for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++) { - if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) - Scores[D.TargetPkg()->ID]+= PrioDepends; + if (D->Type == pkgCache::Dep::Depends || + D->Type == pkgCache::Dep::PreDepends) + Scores[D.TargetPkg()->ID] += PrioDepends; + else if (D->Type == pkgCache::Dep::Recommends) + Scores[D.TargetPkg()->ID] += PrioRecommends; } } @@ -572,7 +577,9 @@ void pkgProblemResolver::MakeScores() { // Only do it for the install version if ((pkgCache::Version *)D.ParentVer() != Cache[D.ParentPkg()].InstallVer || - (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends)) + (D->Type != pkgCache::Dep::Depends && + D->Type != pkgCache::Dep::PreDepends && + D->Type != pkgCache::Dep::Recommends)) continue; Scores[I->ID] += abs(OldScores[D.ParentPkg()->ID]); diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 3d35e4298..28466cd40 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -110,7 +110,7 @@ class pkgCache::VerIterator // Iteration void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return Owner == NULL || (Ver == Owner->VerP?true:false);}; + inline bool end() const {return Owner == 0 || (Ver == Owner->VerP?true:false);}; inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;}; // Comparison @@ -169,7 +169,7 @@ class pkgCache::DescIterator // Iteration void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return Desc == Owner->DescP?true:false;}; + inline bool end() const {return Owner == 0 || Desc == Owner->DescP?true:false;}; inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;}; // Comparison @@ -323,7 +323,7 @@ class pkgCache::PkgFileIterator // Iteration void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return File == Owner->PkgFileP?true:false;}; + inline bool end() const {return Owner == 0 || File == Owner->PkgFileP?true:false;}; // Comparison inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;}; @@ -370,7 +370,7 @@ class pkgCache::VerFileIterator // Iteration void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return FileP == Owner->VerFileP?true:false;}; + inline bool end() const {return Owner == 0 || FileP == Owner->VerFileP?true:false;}; // Comparison inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;}; @@ -402,7 +402,7 @@ class pkgCache::DescFileIterator // Iteration void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return FileP == Owner->DescFileP?true:false;}; + inline bool end() const {return Owner == 0 || FileP == Owner->DescFileP?true:false;}; // Comparison inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;}; diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 891c59836..72d8e4d41 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -16,7 +16,7 @@ #include <unistd.h> #include <stdio.h> #include <algorithm> - +#include <dlfcn.h> #include "indexcopy.h" @@ -681,7 +681,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ { if (_config->FindB("APT::CDROM::NoMount",false) == false) UnmountCdrom(CDROM); - return _error->Error("Unable to locate any package files, perhaps this is not a Debian Disc"); + return _error->Error(_("Unable to locate any package files, perhaps this is not a Debian Disc or the wrong architecture?")); } // Check if the CD is in the database @@ -840,3 +840,87 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ return true; } /*}}}*/ +pkgUdevCdromDevices::pkgUdevCdromDevices() /*{{{*/ + : libudev_handle(NULL) +{ + +} + /*}}}*/ + +bool +pkgUdevCdromDevices::Dlopen() /*{{{*/ +{ + // alread open + if(libudev_handle != NULL) + return true; + + // see if we can get libudev + void *h = ::dlopen("libudev.so.0", RTLD_LAZY); + if(h == NULL) + return false; + + // get the pointers to the udev structs + libudev_handle = h; + udev_new = (udev* (*)(void)) dlsym(h, "udev_new"); + udev_enumerate_add_match_property = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_property"); + udev_enumerate_scan_devices = (int (*)(udev_enumerate*))dlsym(h, "udev_enumerate_scan_devices"); + udev_enumerate_get_list_entry = (udev_list_entry* (*)(udev_enumerate*))dlsym(h, "udev_enumerate_get_list_entry"); + udev_device_new_from_syspath = (udev_device* (*)(udev*, const char*))dlsym(h, "udev_device_new_from_syspath"); + udev_enumerate_get_udev = (udev* (*)(udev_enumerate*))dlsym(h, "udev_enumerate_get_udev"); + udev_list_entry_get_name = (const char* (*)(udev_list_entry*))dlsym(h, "udev_list_entry_get_name"); + udev_device_get_devnode = (const char* (*)(udev_device*))dlsym(h, "udev_device_get_devnode"); + udev_enumerate_new = (udev_enumerate* (*)(udev*))dlsym(h, "udev_enumerate_new"); + udev_list_entry_get_next = (udev_list_entry* (*)(udev_list_entry*))dlsym(h, "udev_list_entry_get_next"); + udev_device_get_property_value = (const char* (*)(udev_device *, const char *))dlsym(h, "udev_device_get_property_value"); + + return true; +} + /*}}}*/ +vector<CdromDevice> +pkgUdevCdromDevices::Scan() /*{{{*/ +{ + vector<CdromDevice> cdrom_devices; + struct udev_enumerate *enumerate; + struct udev_list_entry *l, *devices; + struct udev *udev_ctx; + + if(libudev_handle == NULL) + return cdrom_devices; + + udev_ctx = udev_new(); + enumerate = udev_enumerate_new (udev_ctx); + udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1"); + + udev_enumerate_scan_devices (enumerate); + devices = udev_enumerate_get_list_entry (enumerate); + for (l = devices; l != NULL; l = udev_list_entry_get_next (l)) + { + CdromDevice cdrom; + struct udev_device *udevice; + udevice = udev_device_new_from_syspath (udev_enumerate_get_udev (enumerate), udev_list_entry_get_name (l)); + if (udevice == NULL) + continue; + const char* devnode = udev_device_get_devnode(udevice); + const char* mountpath = udev_device_get_property_value(udevice, "FSTAB_DIR"); + + // fill in the struct + cdrom.DeviceName = string(devnode); + if (mountpath) { + cdrom.MountPath = mountpath; + string s = string(mountpath); + cdrom.Mounted = IsMounted(s); + } else { + cdrom.Mounted = false; + cdrom.MountPath = ""; + } + cdrom_devices.push_back(cdrom); + } + return cdrom_devices; +} + /*}}}*/ + +pkgUdevCdromDevices::~pkgUdevCdromDevices() /*{{{*/ +{ + dlclose(libudev_handle); +} + /*}}}*/ diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h index 608cb0e2f..14ca1d810 100644 --- a/apt-pkg/cdrom.h +++ b/apt-pkg/cdrom.h @@ -67,4 +67,41 @@ class pkgCdrom /*{{{*/ }; /*}}}*/ + +// class that uses libudev to find cdrom devices dynamically +struct CdromDevice /*{{{*/ +{ + string DeviceName; + bool Mounted; + string MountPath; +}; + /*}}}*/ +class pkgUdevCdromDevices /*{{{*/ +{ + protected: + // libudev dlopen stucture + void *libudev_handle; + struct udev* (*udev_new)(void); + int (*udev_enumerate_add_match_property)(struct udev_enumerate *udev_enumerate, const char *property, const char *value); + int (*udev_enumerate_scan_devices)(struct udev_enumerate *udev_enumerate); + struct udev_list_entry* (*udev_enumerate_get_list_entry)(struct udev_enumerate *udev_enumerate); + struct udev_device* (*udev_device_new_from_syspath)(struct udev *udev, const char *syspath); + struct udev* (*udev_enumerate_get_udev)(struct udev_enumerate *udev_enumerate); + const char* (*udev_list_entry_get_name)(struct udev_list_entry *list_entry); + const char* (*udev_device_get_devnode)(struct udev_device *udev_device); + struct udev_enumerate *(*udev_enumerate_new) (struct udev *udev); + struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *list_entry); + const char* (*udev_device_get_property_value)(struct udev_device *udev_device, const char *key); + // end libudev dlopen + + public: + pkgUdevCdromDevices(); + virtual ~pkgUdevCdromDevices(); + + // try to open + bool Dlopen(); + vector<CdromDevice> Scan(); +}; + /*}}}*/ + #endif diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index b6524a178..0cf9697ac 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -98,7 +98,7 @@ bool UnmountCdrom(string Path) // MountCdrom - Mount a cdrom /*{{{*/ // --------------------------------------------------------------------- /* We fork mount and drop all messages */ -bool MountCdrom(string Path) +bool MountCdrom(string Path, string DeviceName) { if (IsMounted(Path) == true) return true; @@ -122,8 +122,15 @@ bool MountCdrom(string Path) { const char *Args[10]; Args[0] = "mount"; - Args[1] = Path.c_str(); - Args[2] = 0; + if (DeviceName == "") + { + Args[1] = Path.c_str(); + Args[2] = 0; + } else { + Args[1] = DeviceName.c_str(); + Args[2] = Path.c_str(); + Args[3] = 0; + } execvp(Args[0],(char **)Args); _exit(100); } diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h index f24bb8c70..9d14249c5 100644 --- a/apt-pkg/contrib/cdromutl.h +++ b/apt-pkg/contrib/cdromutl.h @@ -14,7 +14,8 @@ using std::string; -bool MountCdrom(string Path); +// mount cdrom, DeviceName (e.g. /dev/sr0) is optional +bool MountCdrom(string Path, string DeviceName=""); bool UnmountCdrom(string Path); bool IdentCdrom(string CD,string &Res,unsigned int Version = 2); bool IsMounted(string &Path); diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index a5976cf3a..a7de09c44 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -450,8 +450,11 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap) { if (Reap == true) return false; - if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) - return _error->Error(_("Sub-process %s received a segmentation fault."),Name); + if (WIFSIGNALED(Status) != 0) + if( WTERMSIG(Status) == SIGSEGV) + return _error->Error(_("Sub-process %s received a segmentation fault."),Name); + else + return _error->Error(_("Sub-process %s received signal %u."),Name, WTERMSIG(Status)); if (WIFEXITED(Status) != 0) return _error->Error(_("Sub-process %s returned an error code (%u)"),Name,WEXITSTATUS(Status)); diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 52b9bfbe6..b43771ea7 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -105,11 +105,16 @@ bool Hashes::AddFD(int Fd,unsigned long Size) { unsigned char Buf[64*64]; int Res = 0; - while (Size != 0) + int ToEOF = (Size == 0); + while (Size != 0 || ToEOF) { - Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf))); - if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf))) - return false; + unsigned n = sizeof(Buf); + if (!ToEOF) n = min(Size,(unsigned long)n); + Res = read(Fd,Buf,n); + if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read + return false; + if (ToEOF && Res == 0) // EOF + break; Size -= Res; MD5.Add(Buf,Res); SHA1.Add(Buf,Res); diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc index a095f8f0f..2bfd70f1b 100644 --- a/apt-pkg/contrib/md5.cc +++ b/apt-pkg/contrib/md5.cc @@ -294,11 +294,16 @@ bool MD5Summation::AddFD(int Fd,unsigned long Size) { unsigned char Buf[64*64]; int Res = 0; - while (Size != 0) + int ToEOF = (Size == 0); + while (Size != 0 || ToEOF) { - Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf))); - if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf))) - return false; + unsigned n = sizeof(Buf); + if (!ToEOF) n = min(Size,(unsigned long)n); + Res = read(Fd,Buf,n); + if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read + return false; + if (ToEOF && Res == 0) // EOF + break; Size -= Res; Add(Buf,Res); } diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index aa52b4c30..917466c2f 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -201,7 +201,7 @@ DynamicMMap::~DynamicMMap() if (Fd == 0) { #ifdef _POSIX_MAPPED_FILES - munmap(Base, WorkSpace); + if(munmap(Base, WorkSpace) < 0) #else delete [] (unsigned char *)Base; #endif diff --git a/apt-pkg/contrib/sha256.h b/apt-pkg/contrib/sha256.h index 1951f053b..5934b5641 100644 --- a/apt-pkg/contrib/sha256.h +++ b/apt-pkg/contrib/sha256.h @@ -17,6 +17,7 @@ #include <string> #include <cstring> #include <algorithm> +#include <stdint.h> using std::string; using std::min; diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 61c582b85..a991b8988 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1042,11 +1042,26 @@ void ioprintf(ostream &out,const char *format,...) va_start(args,format); // sprintf the description - char S[400]; + char S[4096]; vsnprintf(S,sizeof(S),format,args); out << S; } /*}}}*/ +// strprintf - C format string outputter to C++ strings /*{{{*/ +// --------------------------------------------------------------------- +/* This is used to make the internationalization strings easier to translate + and to allow reordering of parameters */ +void strprintf(string &out,const char *format,...) +{ + va_list args; + va_start(args,format); + + // sprintf the description + char S[4096]; + vsnprintf(S,sizeof(S),format,args); + out = string(S); +} + /*}}}*/ // safe_snprintf - Safer snprintf /*{{{*/ // --------------------------------------------------------------------- /* This is a snprintf that will never (ever) go past 'End' and returns a @@ -1070,6 +1085,17 @@ char *safe_snprintf(char *Buffer,char *End,const char *Format,...) } /*}}}*/ +// tolower_ascii - tolower() function that ignores the locale /*{{{*/ +// --------------------------------------------------------------------- +/* */ +int tolower_ascii(int c) +{ + if (c >= 'A' and c <= 'Z') + return c + 32; + return c; +} + /*}}}*/ + // CheckDomainList - See if Host is in a , seperate list /*{{{*/ // --------------------------------------------------------------------- /* The domain list is a comma seperate list of domains that are suffix diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 2450bd421..e1f9e3a1f 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -60,8 +60,10 @@ bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length); bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); void ioprintf(ostream &out,const char *format,...) APT_FORMAT2; +void strprintf(string &out,const char *format,...) APT_FORMAT2; char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_FORMAT3; bool CheckDomainList(const string &Host, const string &List); +int tolower_ascii(int c); #define APT_MKSTRCMP(name,func) \ inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \ diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index b2b8b8fb6..517b771a5 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -215,7 +215,7 @@ unsigned short debListParser::VersionHash() for (; Start != End; Start++) { if (isspace(*Start) == 0) - *I++ = tolower(*Start); + *I++ = tolower_ascii(*Start); if (*Start == '<' && Start[1] != '<' && Start[1] != '=') *I++ = '='; if (*Start == '>' && Start[1] != '>' && Start[1] != '=') diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index ccd45d51b..59f826d96 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -67,11 +67,11 @@ bool debSystem::Lock() if (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()); + 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 _error->Error(_("Unable to lock the administration directory (%s), " + "are you root?"),AdminDir.c_str()); } // See if we need to abort with a dirty journal @@ -79,8 +79,8 @@ bool debSystem::Lock() { close(LockFD); LockFD = -1; - return _error->Error("dpkg was interrupted, you must manually " - "run 'dpkg --configure -a' to correct the problem. "); + return _error->Error(_("dpkg was interrupted, you must manually " + "run 'dpkg --configure -a' to correct the problem. ")); } LockCount++; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 85e54988e..f787f365e 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -74,6 +74,31 @@ namespace }; } +/* helper function to ionice the given PID + + there is no C header for ionice yet - just the syscall interface + so we use the binary from util-linux +*/ +static bool +ionice(int PID) +{ + if (!FileExists("/usr/bin/ionice")) + return false; + pid_t Process = ExecFork(); + if (Process == 0) + { + char buf[32]; + snprintf(buf, sizeof(buf), "-p%d", PID); + const char *Args[4]; + Args[0] = "/usr/bin/ionice"; + Args[1] = "-c3"; + Args[2] = buf; + Args[3] = 0; + execv(Args[0], (char **)Args); + } + return ExecWait(Process, "ionice"); +} + // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -587,6 +612,11 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds, */ bool pkgDPkgPM::Go(int OutStatusFd) { + fd_set rfds; + struct timespec tv; + sigset_t sigmask; + sigset_t original_sigmask; + unsigned int MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024); unsigned int MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024); bool NoTriggers = _config->FindB("DPkg::NoTriggers",false); @@ -610,20 +640,12 @@ bool pkgDPkgPM::Go(int OutStatusFd) { {"unpacked",N_("Preparing to configure %s") }, {"half-configured", N_("Configuring %s") }, -#if 0 - {"triggers-awaited", N_("Processing triggers for %s") }, - {"triggers-pending", N_("Processing triggers for %s") }, -#endif { "installed", N_("Installed %s")}, {NULL, NULL} }, // Remove operation { {"half-configured", N_("Preparing for removal of %s")}, -#if 0 - {"triggers-awaited", N_("Preparing for removal of %s")}, - {"triggers-pending", N_("Preparing for removal of %s")}, -#endif {"half-installed", N_("Removing %s")}, {"config-files", N_("Removed %s")}, {NULL, NULL} @@ -660,10 +682,19 @@ bool pkgDPkgPM::Go(int OutStatusFd) for (vector<Item>::iterator I = List.begin(); I != List.end();) { vector<Item>::iterator J = I; - for (; J != List.end() && J->Op == I->Op; J++); + for (; J != List.end() && J->Op == I->Op; J++) + /* nothing */; // Generate the argument list const char *Args[MaxArgs + 50]; + + // Now check if we are within the MaxArgs limit + // + // this code below is problematic, because it may happen that + // the argument list is split in a way that A depends on B + // and they are in the same "--configure A B" run + // - with the split they may now be configured in different + // runs if (J - I > (signed)MaxArgs) J = I + MaxArgs; @@ -796,12 +827,28 @@ bool pkgDPkgPM::Go(int OutStatusFd) rtt = tt; cfmakeraw(&rtt); rtt.c_lflag &= ~ECHO; + // block SIGTTOU during tcsetattr to prevent a hang if + // the process is a member of the background process group + // http://www.opengroup.org/onlinepubs/000095399/functions/tcsetattr.html + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGTTOU); + sigprocmask(SIG_BLOCK,&sigmask, &original_sigmask); tcsetattr(0, TCSAFLUSH, &rtt); + sigprocmask(SIG_SETMASK, &original_sigmask, 0); } // Fork dpkg pid_t Child; _config->Set("APT::Keep-Fds::",fd[1]); + // send status information that we are about to fork dpkg + if(OutStatusFd > 0) { + ostringstream status; + status << "pmstatus:dpkg-exec:" + << (PackagesDone/float(PackagesTotal)*100.0) + << ":" << _("Running dpkg") + << endl; + write(OutStatusFd, status.str().c_str(), status.str().size()); + } Child = ExecFork(); // This is the child @@ -819,6 +866,15 @@ bool pkgDPkgPM::Go(int OutStatusFd) } close(fd[0]); // close the read end of the pipe + if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") + { + std::cerr << "Chrooting into " + << _config->FindDir("DPkg::Chroot-Directory") + << std::endl; + if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0) + _exit(100); + } + if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0) _exit(100); @@ -838,7 +894,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) _exit(100); } - /* No Job Control Stop Env is a magic dpkg var that prevents it from using sigstop */ putenv((char *)"DPKG_NO_TSTP=yes"); @@ -847,6 +902,10 @@ bool pkgDPkgPM::Go(int OutStatusFd) _exit(100); } + // apply ionice + if (_config->FindB("DPkg::UseIoNice", false) == true) + ionice(Child); + // clear the Keep-Fd again _config->Clear("APT::Keep-Fds",fd[1]); @@ -863,10 +922,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) close(slave); // setups fds - fd_set rfds; - struct timespec tv; - sigset_t sigmask; - sigset_t original_sigmask; sigemptyset(&sigmask); sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask); diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index 22ee29697..15696585a 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -522,6 +522,15 @@ bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex) { const indexRecords::checkSum *Record = MetaIndex->Lookup(file); + // we skip non-existing files in the verifcation to support a cdrom + // with no Packages file (just a Package.gz), see LP: #255545 + // (non-existing files are not considered a error) + if(!FileExists(prefix+file)) + { + _error->Warning("Skipping non-exisiting file %s", string(prefix+file).c_str()); + return true; + } + if (!Record) { _error->Warning("Can't find authentication record for: %s",file.c_str()); @@ -651,6 +660,7 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList, if(!Verify(prefix,*I, MetaIndex)) { // something went wrong, don't copy the Release.gpg // FIXME: delete any existing gpg file? + _error->Discard(); continue; } } diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 77fe03d45..1fc27b1a1 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -37,14 +37,14 @@ bool indexRecords::Load(const string Filename) /*{{{*/ pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX if (_error->PendingError() == true) { - ErrorText = _(("Unable to parse Release file " + Filename).c_str()); + strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str()); return false; } pkgTagSection Section; if (TagFile.Step(Section) == false) { - ErrorText = _(("No sections in Release file " + Filename).c_str()); + strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str()); return false; } @@ -78,7 +78,7 @@ bool indexRecords::Load(const string Filename) /*{{{*/ if(HashString::SupportedHashes()[i] == NULL) { - ErrorText = _(("No Hash entry in Release file " + Filename).c_str()); + strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); return false; } diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 059f8532b..92ef58967 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -15,7 +15,7 @@ LIBRARY=apt-pkg LIBEXT=$(GLIBC_VER)$(LIBSTDCPP_VER) MAJOR=4.8 MINOR=0 -SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil +SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl APT_DOMAIN:=libapt-pkg$(MAJOR) # Source code for the contributed non-core things diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 4e10093a8..2a9756c45 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -164,7 +164,7 @@ unsigned long pkgCache::sHash(const string &Str) const { unsigned long Hash = 0; for (string::const_iterator I = Str.begin(); I != Str.end(); I++) - Hash = 5*Hash + tolower(*I); + Hash = 5*Hash + tolower_ascii(*I); return Hash % _count(HeaderP->HashTable); } @@ -172,7 +172,7 @@ unsigned long pkgCache::sHash(const char *Str) const { unsigned long Hash = 0; for (const char *I = Str; *I != 0; I++) - Hash = 5*Hash + tolower(*I); + Hash = 5*Hash + tolower_ascii(*I); return Hash % _count(HeaderP->HashTable); } |