Просмотр исходного кода

* apt-pkg/deb/dpkgpm.cc:
- fix potential hang when in a backgroud process group

Michael Vogt лет назад: 17
Родитель
Сommit
17745b0246
2 измененных файлов с 14 добавлено и 4 удалено
  1. 12 4
      apt-pkg/deb/dpkgpm.cc
  2. 2 0
      debian/changelog

+ 12 - 4
apt-pkg/deb/dpkgpm.cc

@@ -587,6 +587,11 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds,
 */
 */
 bool pkgDPkgPM::Go(int OutStatusFd)
 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 MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024);   
    unsigned int MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024);
    unsigned int MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024);
    bool NoTriggers = _config->FindB("DPkg::NoTriggers",false);
    bool NoTriggers = _config->FindB("DPkg::NoTriggers",false);
@@ -795,7 +800,14 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 	 rtt = tt;
 	 rtt = tt;
 	 cfmakeraw(&rtt);
 	 cfmakeraw(&rtt);
 	 rtt.c_lflag &= ~ECHO;
 	 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);
 	 tcsetattr(0, TCSAFLUSH, &rtt);
+	 sigprocmask(SIG_SETMASK, &original_sigmask, 0);
       }
       }
 
 
        // Fork dpkg
        // Fork dpkg
@@ -862,10 +874,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 	 close(slave);
 	 close(slave);
 
 
       // setups fds
       // setups fds
-      fd_set rfds;
-      struct timespec tv;
-      sigset_t sigmask;
-      sigset_t original_sigmask;
       sigemptyset(&sigmask);
       sigemptyset(&sigmask);
       sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
       sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask);
 
 

+ 2 - 0
debian/changelog

@@ -28,6 +28,8 @@ apt (0.7.17) UNRELEASED; urgency=low
       of variables (LP: #56792)
       of variables (LP: #56792)
   * apt-pkg/cacheiterators.h:
   * apt-pkg/cacheiterators.h:
     - add missing checks for Owner == 0 in end()
     - add missing checks for Owner == 0 in end()
+  * apt-pkg/deb/dpkgpm.cc:
+    - fix potential hang when in a backgroud process group
   
   
   [ Dereck Wonnacott ]
   [ Dereck Wonnacott ]
   * apt-ftparchive might write corrupt Release files (LP: #46439)
   * apt-ftparchive might write corrupt Release files (LP: #46439)