From 608c766dc110493b952a615c3eb82c3cf3ed8b90 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 3 Aug 2007 14:53:51 +0200 Subject: * apt-pkg/init.cc: - init Dir::Log::Terminal * apt-pkg/deb/dpkgpm.cc: - only work with term_out if it is not NULL --- apt-pkg/deb/dpkgpm.cc | 6 ++++-- apt-pkg/init.cc | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index aa840f85e..94215197c 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -843,12 +843,14 @@ bool pkgDPkgPM::Go(int OutStatusFd) if(stopOnError) { - fclose(term_out); + if(term_out) + fclose(term_out); return false; } } } - fclose(term_out); + if(term_out) + fclose(term_out); if (RunScripts("DPkg::Post-Invoke") == false) return false; diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 2617603ec..cc3c1f01c 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -77,7 +77,7 @@ bool pkgInitConfig(Configuration &Cnf) // State Cnf.Set("Dir::Log","var/log/apt"); - Cnf.Set("Dir::Log::Name","term.log"); + Cnf.Set("Dir::Log::Terminal","term.log"); bool Res = true; -- cgit v1.2.3 From a4cf3665915b79ef6dcafd9d1e12b722e0ee5342 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 6 Aug 2007 15:11:48 +0200 Subject: * apt-pkg/deb/dpkgpm.cc: - do not fail if openpty() fails --- apt-pkg/deb/dpkgpm.cc | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 94215197c..68f0a339f 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -706,15 +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]); @@ -723,13 +728,16 @@ bool pkgDPkgPM::Go(int OutStatusFd) // 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) @@ -775,7 +783,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) // the result of the waitpid call int res; - close(slave); + if(slave > 0) + close(slave); // setups fds fd_set rfds; @@ -799,7 +808,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) 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); @@ -808,9 +818,9 @@ bool pkgDPkgPM::Go(int OutStatusFd) 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); @@ -821,7 +831,8 @@ bool pkgDPkgPM::Go(int 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) -- cgit v1.2.3