diff options
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 89 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.h | 5 | ||||
-rw-r--r-- | apt-pkg/init.cc | 1 | ||||
-rw-r--r-- | debian/apt.logrotate | 10 | ||||
-rw-r--r-- | debian/changelog | 22 | ||||
-rw-r--r-- | doc/examples/configure-index | 8 | ||||
-rw-r--r-- | methods/cdrom.cc | 2 | ||||
-rw-r--r-- | methods/http.cc | 79 | ||||
-rw-r--r-- | methods/http.h | 2 |
9 files changed, 181 insertions, 37 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 565f01b84..9d144a227 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -550,12 +550,31 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd) dpkgbuf_pos = dpkgbuf+dpkgbuf_pos-p; } /*}}}*/ +// DPkgPM::WriteHistoryTag /*{{{*/ +void pkgDPkgPM::WriteHistoryTag(string tag, string value) +{ + if (value.size() > 0) + { + // poor mans rstrip(", ") + if (value[value.size()-2] == ',' && value[value.size()-1] == ' ') + value.erase(value.size() - 2, 2); + fprintf(history_out, "%s: %s\n", tag.c_str(), value.c_str()); + } +} /*}}}*/ // DPkgPM::OpenLog /*{{{*/ bool pkgDPkgPM::OpenLog() { string logdir = _config->FindDir("Dir::Log"); if(not FileExists(logdir)) return _error->Error(_("Directory '%s' missing"), logdir.c_str()); + + // get current time + char timestr[200]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + strftime(timestr, sizeof(timestr), "%F %T", tmp); + + // open terminal log string logfile_name = flCombine(logdir, _config->Find("Dir::Log::Terminal")); if (!logfile_name.empty()) @@ -565,31 +584,70 @@ bool pkgDPkgPM::OpenLog() return _error->WarningE(_("Could not open file '%s'"), logfile_name.c_str()); chmod(logfile_name.c_str(), 0600); - // output current time - char outstr[200]; - time_t t = time(NULL); - struct tm *tmp = localtime(&t); - strftime(outstr, sizeof(outstr), "%F %T", tmp); - fprintf(term_out, "\nLog started: %s\n", outstr); + fprintf(term_out, "\nLog started: %s\n", timestr); } + + // write + string history_name = flCombine(logdir, + _config->Find("Dir::Log::History")); + if (!history_name.empty()) + { + history_out = fopen(history_name.c_str(),"a"); + chmod(history_name.c_str(), 0644); + fprintf(history_out, "\nStart-Date: %s\n", timestr); + string remove, purge, install, upgrade, downgrade; + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + { + if (Cache[I].NewInstall()) + install += I.Name() + string(" (") + Cache[I].CandVersion + string("), "); + else if (Cache[I].Upgrade()) + upgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), "); + else if (Cache[I].Downgrade()) + downgrade += I.Name() + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), "); + else if (Cache[I].Delete()) + { + if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge) + purge += I.Name() + string(" (") + Cache[I].CurVersion + string("), "); + else + remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), "); + } + } + WriteHistoryTag("Install", install); + WriteHistoryTag("Upgrade", upgrade); + WriteHistoryTag("Downgrade",downgrade); + WriteHistoryTag("Remove",remove); + WriteHistoryTag("Purge",purge); + fflush(history_out); + } + return true; } /*}}}*/ // DPkg::CloseLog /*{{{*/ bool pkgDPkgPM::CloseLog() { + char timestr[200]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + strftime(timestr, sizeof(timestr), "%F %T", tmp); + if(term_out) { - char outstr[200]; - time_t t = time(NULL); - struct tm *tmp = localtime(&t); - strftime(outstr, sizeof(outstr), "%F %T", tmp); fprintf(term_out, "Log ended: "); - fprintf(term_out, "%s", outstr); + fprintf(term_out, "%s", timestr); fprintf(term_out, "\n"); fclose(term_out); } term_out = NULL; + + if(history_out) + { + if (dpkg_error.size() > 0) + fprintf(history_out, "Error: %s\n", dpkg_error.c_str()); + fprintf(history_out, "End-Date: %s\n", timestr); + fclose(history_out); + } + return true; } /*}}}*/ @@ -1059,11 +1117,14 @@ bool pkgDPkgPM::Go(int OutStatusFd) RunScripts("DPkg::Post-Invoke"); if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) - _error->Error("Sub-process %s received a segmentation fault.",Args[0]); + strprintf(dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]); else if (WIFEXITED(Status) != 0) - _error->Error("Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status)); + strprintf(dpkg_error, "Sub-process %s returned an error code (%u)",Args[0],WEXITSTATUS(Status)); else - _error->Error("Sub-process %s exited unexpectedly",Args[0]); + strprintf(dpkg_error, "Sub-process %s exited unexpectedly",Args[0]); + + if(dpkg_error.size() > 0) + _error->Error(dpkg_error.c_str()); if(stopOnError) { diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index 43e5c7d45..330c788a2 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -29,7 +29,9 @@ class pkgDPkgPM : public pkgPackageManager char dpkgbuf[1024]; int dpkgbuf_pos; FILE *term_out; - + FILE *history_out; + string dpkg_error; + protected: // progress reporting @@ -66,6 +68,7 @@ class pkgDPkgPM : public pkgPackageManager // Helpers bool RunScriptsWithPkgs(const char *Cnf); bool SendV2Pkgs(FILE *F); + void WriteHistoryTag(string tag, string value); // dpkg log bool OpenLog(); diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index d8c201b9d..6310aff11 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -75,6 +75,7 @@ bool pkgInitConfig(Configuration &Cnf) // State Cnf.Set("Dir::Log","var/log/apt"); Cnf.Set("Dir::Log::Terminal","term.log"); + Cnf.Set("Dir::Log::History","history.log"); // Translation Cnf.Set("APT::Acquire::Translation", "environment"); diff --git a/debian/apt.logrotate b/debian/apt.logrotate index 3e924d383..9a6e5d155 100644 --- a/debian/apt.logrotate +++ b/debian/apt.logrotate @@ -1,5 +1,13 @@ /var/log/apt/term.log { - rotate 6 + rotate 12 + monthly + compress + missingok + notifempty +} + +/var/log/apt/history.log { + rotate 12 monthly compress missingok diff --git a/debian/changelog b/debian/changelog index f14e3fe52..c2c3524a6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,8 +2,20 @@ apt (0.7.25.4) UNRELEASED; urgency=low [ Ivan Masár ] * Slovak translation update. Closes: #568294 + + [ Michael Vogt ] + * merged lp:~mvo/apt/history + - this writes a /var/log/apt/history tagfile that contains details + from the transaction (complements term.log) + * methods/http.cc: + - add cache-control headers even if no cache is given to allow + adding options for intercepting proxies + - add Acquire::http::ProxyAutoDetect configuration that + can be used to call a external helper to figure out the + proxy configuration and return it to apt via stdout + (this is a step towards WPAD and zeroconf/avahi support) - -- Christian Perrier <bubulle@debian.org> Wed, 03 Feb 2010 20:08:19 +0100 + -- Michael Vogt <michael.vogt@ubuntu.com> Fri, 18 Dec 2009 16:54:18 +0100 apt (0.7.25.3) unstable; urgency=low @@ -12,7 +24,7 @@ apt (0.7.25.3) unstable; urgency=low [ David Kalnischkies ] * apt-pkg/contrib/macros.h: - - install the header system.h with a new name to be able to use + - install the header system.h with a new name to be able to use it in other headers (Closes: #567662) * cmdline/acqprogress.cc: - Set Mode to Medium so that the correct prefix is used. @@ -21,7 +33,7 @@ apt (0.7.25.3) unstable; urgency=low - generate sha1 and sha256 checksums for dsc (Closes: #567343) * cmdline/apt-get.cc: - don't mark as manually if in download only (Closes: #468180) - + -- Michael Vogt <mvo@debian.org> Mon, 01 Feb 2010 18:41:15 +0100 apt (0.7.25.2) unstable; urgency=low @@ -45,7 +57,7 @@ apt (0.7.25.2) unstable; urgency=low packages that are not in the extended_states file yet (closes: #534920) * ftparchive/writer.{cc,h}: - - merge crash fix for apt-ftparchive on hurd, thanks to + - merge crash fix for apt-ftparchive on hurd, thanks to Samuel Thibault for the patch (closes: #566664) [ David Kalnischkies ] @@ -84,7 +96,7 @@ apt (0.7.25.1) unstable; urgency=low * French manpage translation update * Russian translation update by Yuri Kozlov Closes: #564171 - + [Chris Leick] * spot & fix various typos in all manpages * German manpage translation update diff --git a/doc/examples/configure-index b/doc/examples/configure-index index ddee86388..233fa2b7d 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -329,6 +329,14 @@ Dir "/" // Location of the logfile Log "var/log/apt" { Terminal "term.log"; + History "history.log"; + }; + + // Media + Media + { + // Media AutoDetect mount path + MountPath "/media/apt"; }; // Media diff --git a/methods/cdrom.cc b/methods/cdrom.cc index 6d694e7c9..bf4281e40 100644 --- a/methods/cdrom.cc +++ b/methods/cdrom.cc @@ -219,7 +219,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm) return true; } - bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", false); + bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true); CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/"); if (Debug) clog << "Looking for CDROM at " << CDROM << endl; diff --git a/methods/http.cc b/methods/http.cc index 2dae87a02..b05444691 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -682,23 +682,25 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out) and a no-store directive for archives. */ sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n", Itm->Uri.c_str(),ProperHost.c_str()); - // only generate a cache control header if we actually want to - // use a cache - if (_config->FindB("Acquire::http::No-Cache",false) == false) + } + // generate a cache control header (if needed) + if (_config->FindB("Acquire::http::No-Cache",false) == true) + { + strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n"); + } + else + { + if (Itm->IndexFile == true) { - if (Itm->IndexFile == true) - sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n", - _config->FindI("Acquire::http::Max-Age",0)); - else - { - if (_config->FindB("Acquire::http::No-Store",false) == true) - strcat(Buf,"Cache-Control: no-store\r\n"); - } + sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n", + _config->FindI("Acquire::http::Max-Age",0)); + } + else + { + if (_config->FindB("Acquire::http::No-Store",false) == true) + strcat(Buf,"Cache-Control: no-store\r\n"); } } - // generate a no-cache header if needed - if (_config->FindB("Acquire::http::No-Cache",false) == true) - strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n"); string Req = Buf; @@ -1071,7 +1073,11 @@ bool HttpMethod::Configuration(string Message) PipelineDepth = _config->FindI("Acquire::http::Pipeline-Depth", PipelineDepth); Debug = _config->FindB("Debug::Acquire::http",false); - + AutoDetectProxyCmd = _config->Find("Acquire::http::ProxyAutoDetect"); + + // Get the proxy to use + AutoDetectProxy(); + return true; } /*}}}*/ @@ -1321,6 +1327,49 @@ int HttpMethod::Loop() return 0; } /*}}}*/ +// HttpMethod::AutoDetectProxy - auto detect proxy /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool HttpMethod::AutoDetectProxy() +{ + if (AutoDetectProxyCmd.empty()) + return true; + + if (Debug) + clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << endl; + + int Pipes[2] = {-1,-1}; + if (pipe(Pipes) != 0) + return _error->Errno("pipe", "Failed to create Pipe"); + + pid_t Process = ExecFork(); + if (Process == 0) + { + dup2(Pipes[1],STDOUT_FILENO); + SetCloseExec(STDOUT_FILENO,false); + + const char *Args[2]; + Args[0] = AutoDetectProxyCmd.c_str(); + Args[1] = 0; + execv(Args[0],(char **)Args); + cerr << "Failed to exec method " << Args[0] << endl; + _exit(100); + } + char buf[512]; + int InFd = Pipes[0]; + if (read(InFd, buf, sizeof(buf)) < 0) + return _error->Errno("read", "Failed to read"); + ExecWait(Process, "ProxyAutoDetect"); + + if (Debug) + clog << "auto detect command returned: '" << buf << "'" << endl; + + if (strstr(buf, "http://") == buf) + _config->Set("Acquire::http::proxy", _strstrip(buf)); + + return true; +} + /*}}}*/ int main() { diff --git a/methods/http.h b/methods/http.h index 13f02ec77..ceee36cbe 100644 --- a/methods/http.h +++ b/methods/http.h @@ -134,6 +134,7 @@ class HttpMethod : public pkgAcqMethod bool Flush(ServerState *Srv); bool ServerDie(ServerState *Srv); int DealWithHeaders(FetchResult &Res,ServerState *Srv); + bool AutoDetectProxy(); virtual bool Fetch(FetchItem *); virtual bool Configuration(string Message); @@ -145,6 +146,7 @@ class HttpMethod : public pkgAcqMethod static void SigTerm(int); string NextURI; + string AutoDetectProxyCmd; public: friend class ServerState; |