]> git.saurik.com Git - apt.git/commitdiff
* merged with dpkg-log branch
authorMichael Vogt <michael.vogt@ubuntu.com>
Mon, 6 Aug 2007 13:13:30 +0000 (15:13 +0200)
committerMichael Vogt <michael.vogt@ubuntu.com>
Mon, 6 Aug 2007 13:13:30 +0000 (15:13 +0200)
1  2 
apt-pkg/deb/dpkgpm.cc

diff --combined apt-pkg/deb/dpkgpm.cc
index 168c314836317f9e24787bdcfdb58b78dc4a5a4e,68f0a339f0bbe5d4934edf848dd0c10eb49019ce..e017c1a5b236966baf2f83dcf58e3614ab68c624
@@@ -13,6 -13,7 +13,7 @@@
  #include <apt-pkg/configuration.h>
  #include <apt-pkg/depcache.h>
  #include <apt-pkg/strutl.h>
+ #include <apti18n.h>
  
  #include <unistd.h>
  #include <stdlib.h>
@@@ -43,7 -44,7 +44,7 @@@ using namespace std
  // ---------------------------------------------------------------------
  /* */
  pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) 
 -   : pkgPackageManager(Cache), dpkgbuf_pos(0), PackagesTotal(0), PackagesDone(0)
 +   : pkgPackageManager(Cache), dpkgbuf_pos(0), PackagesDone(0), PackagesTotal(0)
  {
  }
                                                                        /*}}}*/
@@@ -706,15 -707,19 +707,19 @@@ bool pkgDPkgPM::Go(int OutStatusFd
        ioctl(0, TIOCGWINSZ, (char *)&win);
        if (openpty(&master, &slave, NULL, &tt, &win) < 0) 
        {
-        fprintf(stderr, _("openpty failed\n"));
+        const char *s = _("Can not write log, openpty() "
+                          "failed (/dev/pts not mounted?)\n");
+        fprintf(stderr, "%s",s);
+        fprintf(term_out, "%s",s);
+        master = slave = -1;
+       }  else {
+        struct termios rtt;
+        rtt = tt;
+        cfmakeraw(&rtt);
+        rtt.c_lflag &= ~ECHO;
+        tcsetattr(0, TCSAFLUSH, &rtt);
        }
  
-       struct termios rtt;
-       rtt = tt;
-       cfmakeraw(&rtt);
-       rtt.c_lflag &= ~ECHO;
-       tcsetattr(0, TCSAFLUSH, &rtt);
         // Fork dpkg
        pid_t Child;
        _config->Set("APT::Keep-Fds::",fd[1]);
        // This is the child
        if (Child == 0)
        {
-        setsid();
-        ioctl(slave, TIOCSCTTY, 0);
-        close(master);
-        dup2(slave, 0);
-        dup2(slave, 1);
-        dup2(slave, 2);
-        close(slave);
+        if(slave >= 0 && master >= 0) 
+        {
+           setsid();
+           ioctl(slave, TIOCSCTTY, 0);
+           close(master);
+           dup2(slave, 0);
+           dup2(slave, 1);
+           dup2(slave, 2);
+           close(slave);
+        }
         close(fd[0]); // close the read end of the pipe
  
         if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
        int _dpkgin = fd[0];
        close(fd[1]);                        // close the write end of the pipe
  
 -      // the read buffers for the communication with dpkg
 -      char buf[2] = {0,0};
 -      
        // the result of the waitpid call
        int res;
-       close(slave);
+       if(slave > 0)
+        close(slave);
  
        // setups fds
        fd_set rfds;
         FD_ZERO(&rfds);
         FD_SET(0, &rfds); 
         FD_SET(_dpkgin, &rfds);
-        FD_SET(master, &rfds);
+        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);
         else if (select_ret == 0)
            continue;
  
-        if(FD_ISSET(master, &rfds))
+        if(master >= 0 && FD_ISSET(master, &rfds))
            DoTerminalPty(master, term_out);
-        if(FD_ISSET(0, &rfds))
+        if(master >= 0 && FD_ISSET(0, &rfds))
            DoStdin(master);
         if(FD_ISSET(_dpkgin, &rfds))
            DoDpkgStatusFd(_dpkgin, OutStatusFd);
        signal(SIGQUIT,old_SIGQUIT);
        signal(SIGINT,old_SIGINT);
  
-       tcsetattr(0, TCSAFLUSH, &tt);
+       if(master >= 0 && slave >= 0)
+        tcsetattr(0, TCSAFLUSH, &tt);
         
        // Check for an error code.
        if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)