]> git.saurik.com Git - apt.git/commitdiff
merged with apt--mvo
authorMichael Vogt <egon@bottom>
Sat, 20 Oct 2007 05:47:16 +0000 (07:47 +0200)
committerMichael Vogt <egon@bottom>
Sat, 20 Oct 2007 05:47:16 +0000 (07:47 +0200)
1  2 
apt-pkg/deb/dpkgpm.cc

diff --combined apt-pkg/deb/dpkgpm.cc
index 706abcb92c274cf9c9c846b6e222c959f0c200bc,8e1d7c85a813c72f5214c60e54e413c3499e3cfa..ce4d4b44ba0dddbce6019d09630fb0a79dab7c1d
@@@ -357,7 -357,15 +357,15 @@@ void pkgDPkgPM::DoTerminalPty(int maste
     char term_buf[1024] = {0,};
  
     int len=read(master, term_buf, sizeof(term_buf));
-    if(len <= 0)
+    if(len == -1 && errno == EIO)
+    {
+       // this happens when the child is about to exit, we
+       // give it time to actually exit, otherwise we run
+       // into a race
+       usleep(500000);
+       return;
+    }  
+    if(len <= 0) 
        return;
     write(1, term_buf, len);
     if(term_out)
@@@ -495,46 -503,6 +503,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                                      /*{{{*/
  // ---------------------------------------------------------------------
@@@ -611,7 -579,24 +619,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();)
  
        // setups fds
        fd_set rfds;
-       struct timeval tv;
+       struct timespec tv;
+       sigset_t sigmask;
+       sigset_t original_sigmask;
+       sigemptyset(&sigmask);
+       sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
        int select_ret;
        while ((res=waitpid(Child,&Status, WNOHANG)) != Child) {
         if(res < 0) {
         if(master >= 0)
            FD_SET(master, &rfds);
         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;
-        } 
+        tv.tv_nsec = 0;
+        select_ret = pselect(max(master, _dpkgin)+1, &rfds, NULL, NULL, 
+                             &tv, &original_sigmask);
+        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;