]> git.saurik.com Git - apt.git/commitdiff
merged from the dpkg-log branch
authorMichael Vogt <egon@bottom>
Wed, 3 Oct 2007 07:55:04 +0000 (09:55 +0200)
committerMichael Vogt <egon@bottom>
Wed, 3 Oct 2007 07:55:04 +0000 (09:55 +0200)
1  2 
apt-pkg/deb/dpkgpm.cc

diff --combined apt-pkg/deb/dpkgpm.cc
index 92f96620f8cd9b0ee46a609bcbc0087c13194e4a,f83214344ab98e3aa8e034913087a24b7ae52d7d..4323b5fd2a35fb91783224f1c43c2d8afc144ab2
@@@ -44,8 -44,8 +44,8 @@@ using namespace std
  // ---------------------------------------------------------------------
  /* */
  pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) 
 -   : pkgPackageManager(Cache), dpkgbuf_pos(0), PackagesDone(0), 
 -     PackagesTotal(0), term_out(NULL)
 +   : pkgPackageManager(Cache), dpkgbuf_pos(0),
 +     term_out(NULL), PackagesDone(0), PackagesTotal(0)
  {
  }
                                                                        /*}}}*/
@@@ -392,14 -392,14 +392,14 @@@ void pkgDPkgPM::ProcessDpkgStatusLine(i
     //        statusfd or by rewriting the code here to deal with
     //        it. for now we just ignore it and not crash
     TokSplitString(':', line, list, sizeof(list)/sizeof(list[0]));
 -   char *pkg = list[1];
 -   char *action = _strstrip(list[2]);
 -   if( pkg == NULL || action == NULL) 
 +   if( list[0] == NULL || list[1] == NULL || list[2] == NULL) 
     {
        if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)
         std::clog << "ignoring line: not enough ':'" << std::endl;
        return;
     }
 +   char *pkg = list[1];
 +   char *action = _strstrip(list[2]);
  
     if(strncmp(action,"error",strlen("error")) == 0)
     {
@@@ -495,6 -495,46 +495,46 @@@ void pkgDPkgPM::DoDpkgStatusFd(int stat
  }
                                                                        /*}}}*/
  
+ bool pkgDPkgPM::OpenLog()
+ {
+    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::Terminal"));
+    if (!logfile_name.empty())
+    {
+       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, "\nLog started: ");
+       fprintf(term_out, outstr);
+       fprintf(term_out, "\n");
+    }
+    return true;
+ }
+ bool pkgDPkgPM::CloseLog()
+ {
+    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, outstr);
+       fprintf(term_out, "\n");
+       fclose(term_out);
+    }
+    term_out = NULL;
+    return true;
+ }
  
  // DPkgPM::Go - Run the sequence                                      /*{{{*/
  // ---------------------------------------------------------------------
@@@ -518,7 -558,7 +558,7 @@@ bool pkgDPkgPM::Go(int OutStatusFd
     
     // map the dpkg states to the operations that are performed
     // (this is sorted in the same way as Item::Ops)
 -   static const struct DpkgState DpkgStatesOpMap[][5] = {
 +   static const struct DpkgState DpkgStatesOpMap[][7] = {
        // Install operation
        { 
         {"half-installed", N_("Preparing %s")}, 
        { 
         {"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}
     }   
  
     // 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::Terminal"));
-    if (!logfile_name.empty())
-    {
-       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, "\nLog started: ");
-       fprintf(term_out, outstr);
-       fprintf(term_out, "\n");
-    }
+    OpenLog();
  
     // this loop is runs once per operation
     for (vector<Item>::iterator I = List.begin(); I != List.end();)
  
         /* No Job Control Stop Env is a magic dpkg var that prevents it
            from using sigstop */
 -       putenv("DPKG_NO_TSTP=yes");
 +       putenv((char *)"DPKG_NO_TSTP=yes");
         execvp(Args[0],(char **)Args);
         cerr << "Could not exec dpkg!" << endl;
         _exit(100);
         tv.tv_sec = 1;
         tv.tv_usec = 0;
         select_ret = select(max(master, _dpkgin)+1, &rfds, NULL, NULL, &tv);
-        if (select_ret == 0) 
-           continue;
-        else if (select_ret < 0 && errno == EINTR)
-           continue;
-        else if (select_ret < 0) 
-        {
-           perror("select() returned error");
-           continue;
-        } 
-        
+        if (select_ret == 0) 
+           continue;
+        else if (select_ret < 0 && errno == EINTR)
+           continue;
+        else if (select_ret < 0) 
+        {
+           perror("select() returned error");
+           continue;
+        } 
 -
         if(master >= 0 && FD_ISSET(master, &rfds))
            DoTerminalPty(master);
         if(master >= 0 && FD_ISSET(0, &rfds))
  
         if(stopOnError) 
         {
-           if(term_out)
-              fclose(term_out);
+           CloseLog();
            return false;
         }
        }      
     }
-    if(term_out)
-       fclose(term_out);
+    CloseLog();
  
     if (RunScripts("DPkg::Post-Invoke") == false)
        return false;