+ /*}}}*/
+
+// DPkgPM::BuildPackagesProgressMap /*{{{*/
+void pkgDPkgPM::BuildPackagesProgressMap()
+{
+ // map the dpkg states to the operations that are performed
+ // (this is sorted in the same way as Item::Ops)
+ static const struct DpkgState DpkgStatesOpMap[][7] = {
+ // Install operation
+ {
+ {"half-installed", N_("Preparing %s")},
+ {"unpacked", N_("Unpacking %s") },
+ {NULL, NULL}
+ },
+ // Configure operation
+ {
+ {"unpacked",N_("Preparing to configure %s") },
+ {"half-configured", N_("Configuring %s") },
+ { "installed", N_("Installed %s")},
+ {NULL, NULL}
+ },
+ // Remove operation
+ {
+ {"half-configured", N_("Preparing for removal of %s")},
+ {"half-installed", N_("Removing %s")},
+ {"config-files", N_("Removed %s")},
+ {NULL, NULL}
+ },
+ // Purge operation
+ {
+ {"config-files", N_("Preparing to completely remove %s")},
+ {"not-installed", N_("Completely removed %s")},
+ {NULL, NULL}
+ },
+ };
+
+ // init the PackageOps map, go over the list of packages that
+ // that will be [installed|configured|removed|purged] and add
+ // them to the PackageOps map (the dpkg states it goes through)
+ // and the PackageOpsTranslations (human readable strings)
+ for (vector<Item>::const_iterator I = List.begin(); I != List.end(); ++I)
+ {
+ if((*I).Pkg.end() == true)
+ continue;
+
+ string const name = (*I).Pkg.FullName();
+ PackageOpsDone[name] = 0;
+ for(int i=0; (DpkgStatesOpMap[(*I).Op][i]).state != NULL; ++i)
+ {
+ PackageOps[name].push_back(DpkgStatesOpMap[(*I).Op][i]);
+ PackagesTotal++;
+ }
+ }
+}
+ /*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
+bool pkgDPkgPM::Go(int StatusFd)
+{
+ APT::Progress::PackageManager *progress = NULL;
+ if (StatusFd == -1)
+ progress = APT::Progress::PackageManagerProgressFactory();
+ else
+ progress = new APT::Progress::PackageManagerProgressFd(StatusFd);
+
+ return GoNoABIBreak(progress);
+}
+#endif
+
+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;
+
+ // if tcgetattr for both stdin/stdout returns 0 (no error)
+ // we do the pty magic
+ _error->PushToStack();
+ if (tcgetattr(STDIN_FILENO, &d->tt) == 0 &&
+ tcgetattr(STDOUT_FILENO, &d->tt) == 0)
+ {
+ if (ioctl(STDOUT_FILENO, 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;
+ } else {
+ struct termios rtt;
+ rtt = d->tt;
+ cfmakeraw(&rtt);
+ rtt.c_lflag &= ~ECHO;
+ rtt.c_lflag |= ISIG;
+ // 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(&d->sigmask);
+ sigaddset(&d->sigmask, SIGTTOU);
+ sigprocmask(SIG_BLOCK,&d->sigmask, &d->original_sigmask);
+ tcsetattr(0, TCSAFLUSH, &rtt);
+ sigprocmask(SIG_SETMASK, &d->original_sigmask, 0);
+ }
+ }
+ // complain only if stdout is either a terminal (but still failed) or is an invalid
+ // descriptor otherwise we would complain about redirection to e.g. /dev/null as well.
+ else if (isatty(STDOUT_FILENO) == 1 || errno == EBADF)
+ _error->Errno("tcgetattr", _("Can not write log (%s)"), _("Is stdout a terminal?"));
+
+ if (_error->PendingError() == true)
+ _error->DumpErrors(std::cerr);
+ _error->RevertToStack();
+}
+
+void pkgDPkgPM::StopPtyMagic()
+{
+ if(d->slave > 0)
+ close(d->slave);
+ if(d->master >= 0)
+ {
+ tcsetattr(0, TCSAFLUSH, &d->tt);
+ close(d->master);
+ }
+}
+