Browse Source

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

Michael Vogt 19 years ago
parent
commit
ff56e98015
5 changed files with 42 additions and 25 deletions
  1. 28 20
      apt-pkg/deb/dpkgpm.cc
  2. 4 5
      apt-pkg/deb/dpkgpm.h
  3. 4 0
      apt-pkg/init.cc
  4. 1 0
      debian/apt.dirs
  5. 5 0
      doc/examples/configure-index

+ 28 - 20
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;

+ 4 - 5
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);

+ 4 - 0
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;
    

+ 1 - 0
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

+ 5 - 0
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