Merge remote-tracking branch 'donkult/debian/sid' into debian/sid
[ntk/apt.git] / apt-pkg / deb / dpkgpm.cc
index b4bfd14..91893c4 100644 (file)
@@ -44,6 +44,7 @@
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <pty.h>
+#include <stdio.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -567,7 +568,6 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
    std::string prefix = APT::String::Strip(list[0]);
    std::string pkgname;
    std::string action;
-   ostringstream status;
 
    // "processing" has the form "processing: action: pkg or trigger"
    // with action = ["install", "configure", "remove", "purge", "disappear",
@@ -596,7 +596,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
       errors look like this:
       'status: /var/cache/apt/archives/krecipes_0.8.1-0ubuntu1_i386.deb : error : trying to overwrite `/usr/share/doc/kde/HTML/en/krecipes/krectip.png', which is also in package krecipes-data 
       and conffile-prompt like this
-      'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited
+      'status:/etc/compiz.conf/compiz.conf :  conffile-prompt: 'current-conffile' 'new-conffile' useredited distedited
    */
    if (prefix == "status")
    {
@@ -608,7 +608,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
          WriteApportReport(list[1].c_str(), list[3].c_str());
          return;
       }
-      else if(action == "conffile")
+      else if(action == "conffile-prompt")
       {
          d->progress->ConffilePrompt(list[1], PackagesDone, PackagesTotal,
                                      list[3]);
@@ -1027,6 +1027,12 @@ bool pkgDPkgPM::Go(int StatusFd)
 
 void pkgDPkgPM::StartPtyMagic()
 {
+   if (_config->FindB("Dpkg::Use-Pty", true) == false)
+   {
+      d->master = d->slave = -1;
+      return;
+   }
+
    // setup the pty and stuff
    struct      winsize win;
 
@@ -1035,8 +1041,10 @@ void pkgDPkgPM::StartPtyMagic()
    _error->PushToStack();
    if (tcgetattr(STDOUT_FILENO, &d->tt) == 0)
    {
-       ioctl(1, TIOCGWINSZ, (char *)&win);
-       if (openpty(&d->master, &d->slave, NULL, &d->tt, &win) < 0)
+       if (ioctl(1, TIOCGWINSZ, (char *)&win) < 0)
+       {
+           _error->Errno("ioctl", _("ioctl(TIOCGWINSZ) failed"));
+       } else if (openpty(&d->master, &d->slave, NULL, &d->tt, &win) < 0)
        {
            _error->Errno("openpty", _("Can not write log (%s)"), _("Is /dev/pts mounted?"));
            d->master = d->slave = -1;
@@ -1182,7 +1190,7 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
    StartPtyMagic();
 
    // Tell the progress that its starting and fork dpkg 
-   d->progress->Start();
+   d->progress->Start(d->master);
 
    // this loop is runs once per dpkg operation
    vector<Item>::const_iterator I = List.begin();
@@ -1389,12 +1397,17 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
         if(d->slave >= 0 && d->master >= 0) 
         {
            setsid();
-           ioctl(d->slave, TIOCSCTTY, 0);
-           close(d->master);
-           dup2(d->slave, 0);
-           dup2(d->slave, 1);
-           dup2(d->slave, 2);
-           close(d->slave);
+           int res = ioctl(d->slave, TIOCSCTTY, 0);
+            if (res < 0) {
+               std::cerr << "ioctl(TIOCSCTTY) failed for fd: " 
+                         << d->slave << std::endl;
+            } else {
+               close(d->master);
+               dup2(d->slave, 0);
+               dup2(d->slave, 1);
+               dup2(d->slave, 2);
+               close(d->slave);
+            }
         }
         close(fd[0]); // close the read end of the pipe
 
@@ -1648,7 +1661,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    io_errors.push_back(string("failed in write on buffer copy for %s"));
    io_errors.push_back(string("short read on buffer copy for %s"));
 
-   for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); I++)
+   for (vector<string>::iterator I = io_errors.begin(); I != io_errors.end(); ++I)
    {
       vector<string> list = VectorizeString(dgettext("dpkg", (*I).c_str()), '%');
       if (list.size() > 1) {
@@ -1763,13 +1776,11 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
    string histfile_name = _config->FindFile("Dir::Log::History");
    if (!histfile_name.empty())
    {
-      FILE *log = NULL;
-      char buf[1024];
-
       fprintf(report, "DpkgHistoryLog:\n");
-      log = fopen(histfile_name.c_str(),"r");
+      FILE* log = fopen(histfile_name.c_str(),"r");
       if(log != NULL)
       {
+        char buf[1024];
         while( fgets(buf, sizeof(buf), log) != NULL)
            fprintf(report, " %s", buf);
         fclose(log);