]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
* remove the MarkKeep calls if Is{Delete,Install}Ok false, because
[apt.git] / apt-pkg / deb / dpkgpm.cc
index 77143e67175e05f6799c851082fe68629a4ccc8b..85e54988e8beb104720d7204f7126c2793cd7ae3 100644 (file)
@@ -25,6 +25,8 @@
 #include <signal.h>
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
+#include <algorithm>
 #include <sstream>
 #include <map>
 
 
 using namespace std;
 
-
+namespace
+{
+  // Maps the dpkg "processing" info to human readable names.  Entry 0
+  // of each array is the key, entry 1 is the value.
+  const std::pair<const char *, const char *> PackageProcessingOps[] = {
+    std::make_pair("install",   N_("Installing %s")),
+    std::make_pair("configure", N_("Configuring %s")),
+    std::make_pair("remove",    N_("Removing %s")),
+    std::make_pair("trigproc",  N_("Running post-installation trigger %s"))
+  };
+
+  const std::pair<const char *, const char *> * const PackageProcessingOpsBegin = PackageProcessingOps;
+  const std::pair<const char *, const char *> * const PackageProcessingOpsEnd   = PackageProcessingOps + sizeof(PackageProcessingOps) / sizeof(PackageProcessingOps[0]);
+
+  // Predicate to test whether an entry in the PackageProcessingOps
+  // array matches a string.
+  class MatchProcessingOp
+  {
+    const char *target;
+
+  public:
+    MatchProcessingOp(const char *the_target)
+      : target(the_target)
+    {
+    }
+
+    bool operator()(const std::pair<const char *, const char *> &pair) const
+    {
+      return strcmp(pair.first, target) == 0;
+    }
+  };
+}
 
 // DPkgPM::pkgDPkgPM - Constructor                                     /*{{{*/
 // ---------------------------------------------------------------------
@@ -362,17 +395,19 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
    if(strncmp(list[0], "processing", strlen("processing")) == 0)
    {
       char s[200];
-      map<string,string>::iterator iter;
       char *pkg_or_trigger = _strstrip(list[2]);
       action =_strstrip( list[1]);
-      iter = PackageProcessingOps.find(action);
-      if(iter == PackageProcessingOps.end())
+      const std::pair<const char *, const char *> * const iter =
+       std::find_if(PackageProcessingOpsBegin,
+                    PackageProcessingOpsEnd,
+                    MatchProcessingOp(action));
+      if(iter == PackageProcessingOpsEnd)
       {
         if (_config->FindB("Debug::pkgDPkgProgressReporting",false) == true)
            std::clog << "ignoring unknwon action: " << action << std::endl;
         return;
       }
-      snprintf(s, sizeof(s), _(iter->second.c_str()), pkg_or_trigger);
+      snprintf(s, sizeof(s), _(iter->second), pkg_or_trigger);
 
       status << "pmstatus:" << pkg_or_trigger
             << ":"  << (PackagesDone/float(PackagesTotal)*100.0) 
@@ -496,7 +531,7 @@ bool pkgDPkgPM::OpenLog()
       struct tm *tmp = localtime(&t);
       strftime(outstr, sizeof(outstr), "%F  %T", tmp);
       fprintf(term_out, "\nLog started: ");
-      fprintf(term_out, outstr);
+      fprintf(term_out, "%s", outstr);
       fprintf(term_out, "\n");
    }
    return true;
@@ -511,7 +546,7 @@ bool pkgDPkgPM::CloseLog()
       struct tm *tmp = localtime(&t);
       strftime(outstr, sizeof(outstr), "%F  %T", tmp);
       fprintf(term_out, "Log ended: ");
-      fprintf(term_out, outstr);
+      fprintf(term_out, "%s", outstr);
       fprintf(term_out, "\n");
       fclose(term_out);
    }
@@ -554,6 +589,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 {
    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);
 
    if (RunScripts("DPkg::Pre-Invoke") == false)
       return false;
@@ -600,12 +636,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       },
    };
 
-   // populate the "processing" map
-   PackageProcessingOps.insert( make_pair("install",N_("Installing %s")) );
-   PackageProcessingOps.insert( make_pair("configure",N_("Configuring %s")) );
-   PackageProcessingOps.insert( make_pair("remove",N_("Removing %s")) );
-   PackageProcessingOps.insert( make_pair("trigproc",N_("Running post-installation trigger %s")) );
-
    // init the PackageOps map, go over the list of packages that
    // that will be [installed|configured|removed|purged] and add
    // them to the PackageOps map (the dpkg states it goes through)
@@ -689,6 +719,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         
         case Item::Configure:
         Args[n++] = "--configure";
+        if (NoTriggers)
+           Args[n++] = "--no-triggers";
         Size += strlen(Args[n-1]);
         break;
         
@@ -741,17 +773,18 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN);
       sighandler_t old_SIGINT = signal(SIGINT,SIG_IGN);
 
+      // ignore SIGHUP as well (debian #463030)
+      sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN);
+
       struct   termios tt;
-      struct   termios tt_out;
       struct   winsize win;
       int      master;
       int      slave;
 
       // FIXME: setup sensible signal handling (*ick*)
       tcgetattr(0, &tt);
-      tcgetattr(1, &tt_out);
       ioctl(0, TIOCGWINSZ, (char *)&win);
-      if (openpty(&master, &slave, NULL, &tt_out, &win) < 0) 
+      if (openpty(&master, &slave, NULL, &tt, &win) < 0) 
       {
         const char *s = _("Can not write log, openpty() "
                           "failed (/dev/pts not mounted?)\n");
@@ -849,6 +882,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            // Restore sig int/quit
            signal(SIGQUIT,old_SIGQUIT);
            signal(SIGINT,old_SIGINT);
+           signal(SIGHUP,old_SIGHUP);
            return _error->Errno("waitpid","Couldn't wait for subprocess");
         }
 
@@ -888,6 +922,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       // Restore sig int/quit
       signal(SIGQUIT,old_SIGQUIT);
       signal(SIGINT,old_SIGINT);
+      signal(SIGHUP,old_SIGHUP);
 
       if(master >= 0) 
       {
@@ -924,6 +959,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 
    if (RunScripts("DPkg::Post-Invoke") == false)
       return false;
+
+   Cache.writeStateFile(NULL);
    return true;
 }
                                                                        /*}}}*/