X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/0f2fa32291a66b7a154b5926a6dc8f38476bdd94..47f17da4f65ee4887f46e4442ce2843e3e744d89:/apt-pkg/deb/dpkgpm.cc diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index ae761ec4d..85d46edba 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: dpkgpm.cc,v 1.19 2001/02/22 06:26:27 jgg Exp $ +// $Id: dpkgpm.cc,v 1.28 2004/01/27 02:25:01 mdz Exp $ /* ###################################################################### DPKG Package Manager - Provide an interface to dpkg @@ -16,7 +16,7 @@ #include #include #include - + #include #include #include @@ -25,8 +25,11 @@ #include #include #include +#include /*}}}*/ +using namespace std; + // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -141,7 +144,6 @@ bool pkgDPkgPM::RunScripts(const char *Cnf) return true; } - /*}}}*/ // DPkgPM::SendV2Pkgs - Send version 2 package info /*{{{*/ // --------------------------------------------------------------------- @@ -312,12 +314,6 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) Die = !SendV2Pkgs(F); fclose(F); - if (Die == true) - { - kill(Process,SIGINT); - ExecWait(Process,Opts->Value.c_str(),true); - return _error->Error("Failure running script %s",Opts->Value.c_str()); - } // Clean up the sub process if (ExecWait(Process,Opts->Value.c_str()) == false) @@ -326,13 +322,15 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) return true; } - /*}}}*/ // DPkgPM::Go - Run the sequence /*{{{*/ // --------------------------------------------------------------------- /* This globs the operations and calls dpkg */ bool pkgDPkgPM::Go() { + unsigned int MaxArgs = _config->FindI("Dpkg::MaxArgs",8*1024); + unsigned int MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes",32*1024); + if (RunScripts("DPkg::Pre-Invoke") == false) return false; @@ -345,13 +343,14 @@ bool pkgDPkgPM::Go() for (; J != List.end() && J->Op == I->Op; J++); // Generate the argument list - const char *Args[400]; - if (J - I > 350) - J = I + 350; + const char *Args[MaxArgs + 50]; + if (J - I > (signed)MaxArgs) + J = I + MaxArgs; unsigned int n = 0; unsigned long Size = 0; - Args[n++] = _config->Find("Dir::Bin::dpkg","dpkg").c_str(); + string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + Args[n++] = Tmp.c_str(); Size += strlen(Args[n-1]); // Stick in any custom dpkg options @@ -402,7 +401,7 @@ bool pkgDPkgPM::Go() // Write in the file or package names if (I->Op == Item::Install) { - for (;I != J && Size < 1024; I++) + for (;I != J && Size < MaxArgBytes; I++) { if (I->File[0] != '/') return _error->Error("Internal Error, Pathname to install is not absolute '%s'",I->File.c_str()); @@ -412,7 +411,7 @@ bool pkgDPkgPM::Go() } else { - for (;I != J && Size < 1024; I++) + for (;I != J && Size < MaxArgBytes; I++) { Args[n++] = I->Pkg.Name(); Size += strlen(Args[n-1]); @@ -437,8 +436,8 @@ bool pkgDPkgPM::Go() it forks scripts. What happens is that when you hit ctrl-c it sends it to all processes in the group. Since dpkg ignores the signal it doesn't die but we do! So we must also ignore it */ - signal(SIGQUIT,SIG_IGN); - signal(SIGINT,SIG_IGN); + sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN); + sighandler_t old_SIGINT = signal(SIGINT,SIG_IGN); // Fork dpkg pid_t Child = ExecFork(); @@ -449,7 +448,7 @@ bool pkgDPkgPM::Go() if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0) _exit(100); - if (_config->FindB("DPkg::FlushSTDIN",true) == true) + if (_config->FindB("DPkg::FlushSTDIN",true) == true && isatty(STDIN_FILENO)) { int Flags,dummy; if ((Flags = fcntl(STDIN_FILENO,F_GETFL,dummy)) < 0) @@ -480,12 +479,16 @@ bool pkgDPkgPM::Go() if (errno == EINTR) continue; RunScripts("DPkg::Post-Invoke"); + + // Restore sig int/quit + signal(SIGQUIT,old_SIGQUIT); + signal(SIGINT,old_SIGINT); return _error->Errno("waitpid","Couldn't wait for subprocess"); } // Restore sig int/quit - signal(SIGQUIT,SIG_DFL); - signal(SIGINT,SIG_DFL); + signal(SIGQUIT,old_SIGQUIT); + signal(SIGINT,old_SIGINT); // Check for an error code. if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)