diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2007-07-19 10:37:05 +0100 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2007-07-19 10:37:05 +0100 |
commit | ff56e98015b17c73a3f1aacf3deef5ec4ef4e21b (patch) | |
tree | c526aeb7f771d9ff4d27341646fa7d7f2540c55b | |
parent | 09fa2df2f4717ac956210d43e3f3465d6ef5b82b (diff) | |
download | apt-ff56e98015b17c73a3f1aacf3deef5ec4ef4e21b.tar.gz |
apt-pkg/deb/dpkgpm.{cc,h}
- a bit cleanup
- move the log date to the right place
- write log to dir::log::name
apt-pkg/init.cc:
- init dir::log::name "/var/log/apt/term.log"
debian/apt.dirs:
- create /var/log/apt/
doc/examples/configure-index:
- add new dir::log::name to the index
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 48 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.h | 9 | ||||
-rw-r--r-- | apt-pkg/init.cc | 4 | ||||
-rw-r--r-- | debian/apt.dirs | 1 | ||||
-rw-r--r-- | doc/examples/configure-index | 5 |
5 files changed, 42 insertions, 25 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index bef35ab4c..8cb076edd 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -43,7 +43,7 @@ using namespace std; // --------------------------------------------------------------------- /* */ pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) - : pkgPackageManager(Cache), dpkgbuf_pos(0), Total(0), Done(0) + : pkgPackageManager(Cache), dpkgbuf_pos(0), PackagesTotal(0), PackagesDone(0) { } /*}}}*/ @@ -401,7 +401,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) if(strncmp(action,"error",strlen("error")) == 0) { status << "pmerror:" << list[1] - << ":" << (Done/float(Total)*100.0) + << ":" << (PackagesDone/float(PackagesTotal)*100.0) << ":" << list[3] << endl; if(OutStatusFd > 0) @@ -413,7 +413,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) if(strncmp(action,"conffile",strlen("conffile")) == 0) { status << "pmconffile:" << list[1] - << ":" << (Done/float(Total)*100.0) + << ":" << (PackagesDone/float(PackagesTotal)*100.0) << ":" << list[3] << endl; if(OutStatusFd > 0) @@ -438,10 +438,10 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) // we moved from one dpkg state to a new one, report that PackageOpsDone[pkg]++; - Done++; + PackagesDone++; // build the status str status << "pmstatus:" << pkg - << ":" << (Done/float(Total)*100.0) + << ":" << (PackagesDone/float(PackagesTotal)*100.0) << ":" << s << endl; if(OutStatusFd > 0) @@ -555,10 +555,27 @@ bool pkgDPkgPM::Go(int OutStatusFd) for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; i++) { PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]); - Total++; + PackagesTotal++; } } + // create log + string logdir = _config->FindDir("Dir::Log"); + if(not FileExists(logdir)) + return _error->Error(_("Directory '%s' missing"), logdir.c_str()); + string logfile_name = flCombine(logdir, + _config->Find("Dir::Log::Name")); + FILE *term_out = fopen(logfile_name.c_str(),"a"); + 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, "Log started: "); + fprintf(term_out, outstr); + fprintf(term_out, "\n"); + // this loop is runs once per operation for (vector<Item>::iterator I = List.begin(); I != List.end();) { @@ -755,18 +772,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) int res; close(slave); - // FIXME: make this a apt config option and add a logrotate file - FILE *term_out = fopen("/var/log/dpkg-out.log","a"); - chmod("/var/log/dpkg-out.log", 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, "Log started: "); - fprintf(term_out, outstr); - fprintf(term_out, "\n"); - // setups fds fd_set rfds; struct timeval tv; @@ -806,7 +811,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) DoDpkgStatusFd(_dpkgin, OutStatusFd); } close(_dpkgin); - fclose(term_out); // Restore sig int/quit signal(SIGQUIT,old_SIGQUIT); @@ -832,10 +836,14 @@ bool pkgDPkgPM::Go(int OutStatusFd) else _error->Error("Sub-process %s exited unexpectedly",Args[0]); - if(stopOnError) + if(stopOnError) + { + fclose(term_out); return false; + } } } + fclose(term_out); if (RunScripts("DPkg::Post-Invoke") == false) return false; diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index c7792aba4..c552b20c9 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -27,6 +27,8 @@ class pkgDPkgPM : public pkgPackageManager char dpkgbuf[1024]; int dpkgbuf_pos; + protected: + // progress reporting struct DpkgState { @@ -43,10 +45,8 @@ class pkgDPkgPM : public pkgPackageManager // going to be install is already in state "half-installed") map<string,int> PackageOpsDone; // progress reporting - int Done; - int Total; - - protected: + int PackagesDone; + int PackagesTotal; struct Item { @@ -71,7 +71,6 @@ class pkgDPkgPM : public pkgPackageManager void DoDpkgStatusFd(int statusfd, int OutStatusFd); void ProcessDpkgStatusLine(int OutStatusFd, char *line); - // The Actuall installation implementation virtual bool Install(PkgIterator Pkg,string File); virtual bool Configure(PkgIterator Pkg); diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 2f15486d9..2617603ec 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -74,6 +74,10 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.Set("Dir::Etc::parts","apt.conf.d"); Cnf.Set("Dir::Etc::preferences","preferences"); Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods"); + + // State + Cnf.Set("Dir::Log","var/log/apt"); + Cnf.Set("Dir::Log::Name","term.log"); bool Res = true; diff --git a/debian/apt.dirs b/debian/apt.dirs index 1543e8bb1..26bb0683c 100644 --- a/debian/apt.dirs +++ b/debian/apt.dirs @@ -7,4 +7,5 @@ etc/apt/sources.list.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/apt/periodic +var/log/apt usr/share/bug/apt diff --git a/doc/examples/configure-index b/doc/examples/configure-index index d0aad1e3d..0bf407a4d 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -227,6 +227,11 @@ Dir "/" apt-get "/usr/bin/apt-get"; apt-cache "/usr/bin/apt-cache"; }; + + // Location of the logfile + Log "var/log/apt" { + Name "term.log"; + }; }; // Things that effect the APT dselect method |