]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
* apt-pkg/deb/dpkgpm.cc:
[apt.git] / apt-pkg / deb / dpkgpm.cc
index 70dd09bc6ca9d3e3b65d7689f9078b658a984f1e..36c20ad85b0ce56da33501121c24359d438a0619 100644 (file)
@@ -531,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;
@@ -546,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);
    }
@@ -587,6 +587,11 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds,
 */
 bool pkgDPkgPM::Go(int OutStatusFd)
 {
+   fd_set rfds;
+   struct timespec tv;
+   sigset_t sigmask;
+   sigset_t original_sigmask;
+
    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);
@@ -795,7 +800,14 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         rtt = tt;
         cfmakeraw(&rtt);
         rtt.c_lflag &= ~ECHO;
+        // block SIGTTOU during tcsetattr to prevent a hang if
+        // the process is a member of the background process group
+        // http://www.opengroup.org/onlinepubs/000095399/functions/tcsetattr.html
+        sigemptyset(&sigmask);
+        sigaddset(&sigmask, SIGTTOU);
+        sigprocmask(SIG_BLOCK,&sigmask, &original_sigmask);
         tcsetattr(0, TCSAFLUSH, &rtt);
+        sigprocmask(SIG_SETMASK, &original_sigmask, 0);
       }
 
        // Fork dpkg
@@ -862,10 +874,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
         close(slave);
 
       // setups fds
-      fd_set rfds;
-      struct timespec tv;
-      sigset_t sigmask;
-      sigset_t original_sigmask;
       sigemptyset(&sigmask);
       sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
 
@@ -956,6 +964,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 
    if (RunScripts("DPkg::Post-Invoke") == false)
       return false;
+
+   Cache.writeStateFile(NULL);
    return true;
 }
                                                                        /*}}}*/