]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
* apt-pkg/acquire.cc:
[apt.git] / apt-pkg / deb / dpkgpm.cc
index dad8da9edc5befdb915e2e117360b1201533913d..7e1933f062f5da9f4562dbc65891a3f3a5f998a5 100644 (file)
@@ -498,6 +498,46 @@ void pkgDPkgPM::DoDpkgStatusFd(int statusfd, int OutStatusFd)
 }
                                                                        /*}}}*/
 
+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                                       /*{{{*/
 // ---------------------------------------------------------------------
@@ -521,7 +561,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")}, 
@@ -532,12 +572,20 @@ bool pkgDPkgPM::Go(int OutStatusFd)
       { 
         {"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}
@@ -566,24 +614,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
    }   
 
    // 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();)
@@ -813,11 +844,16 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         tv.tv_sec = 1;
         tv.tv_usec = 0;
         select_ret = select(max(master, _dpkgin)+1, &rfds, NULL, NULL, &tv);
-        if (select_ret < 0)
-           std::cerr << "Error in select()" << std::endl;
-        else if (select_ret == 0)
-           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))
@@ -854,14 +890,12 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 
         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;