diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/cachefile.cc | 6 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 67 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 1 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 56 |
4 files changed, 75 insertions, 55 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 96d9672c2..8b8e6dc98 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -24,6 +24,7 @@ #include <apt-pkg/policy.h> #include <apt-pkg/pkgsystem.h> #include <apt-pkg/acquire-item.h> +#include <apt-pkg/fileutl.h> #include <apti18n.h> /*}}}*/ @@ -123,6 +124,9 @@ bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List) if (List.GetIndexes(&Fetcher) == false) return false; + // Run scripts + RunScripts("APT::Update::Pre-Invoke"); + // Run it if (Fetcher.Run() == pkgAcquire::Failed) return false; @@ -152,6 +156,8 @@ bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List) return false; } + // Run the scripts + RunScripts("APT::Update::Post-Invoke"); return (Failed == false); } diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 9fd71728e..77287952a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -8,9 +8,12 @@ CopyFile - Buffered copy of a single file GetLock - dpkg compatible lock file manipulation (fcntl) - This source is placed in the Public Domain, do with it what you will + Most of this source is placed in the Public Domain, do with it what + you will It was originally written by Jason Gunthorpe <jgg@debian.org>. + The exception is RunScripts() it is under the GPLv2 + ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ @@ -38,6 +41,68 @@ using namespace std; +// RunScripts - Run a set of scripts from a configuration subtree /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool RunScripts(const char *Cnf) +{ + Configuration::Item const *Opts = _config->Tree(Cnf); + if (Opts == 0 || Opts->Child == 0) + return true; + Opts = Opts->Child; + + // Fork for running the system calls + pid_t Child = ExecFork(); + + // This is the child + if (Child == 0) + { + if (chdir("/tmp/") != 0) + _exit(100); + + unsigned int Count = 1; + for (; Opts != 0; Opts = Opts->Next, Count++) + { + if (Opts->Value.empty() == true) + continue; + + if (system(Opts->Value.c_str()) != 0) + _exit(100+Count); + } + _exit(0); + } + + // Wait for the child + int Status = 0; + while (waitpid(Child,&Status,0) != Child) + { + if (errno == EINTR) + continue; + return _error->Errno("waitpid","Couldn't wait for subprocess"); + } + + // Restore sig int/quit + signal(SIGQUIT,SIG_DFL); + signal(SIGINT,SIG_DFL); + + // Check for an error code. + if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) + { + unsigned int Count = WEXITSTATUS(Status); + if (Count > 100) + { + Count -= 100; + for (; Opts != 0 && Count != 1; Opts = Opts->Next, Count--); + _error->Error("Problem executing scripts %s '%s'",Cnf,Opts->Value.c_str()); + } + + return _error->Error("Sub-process returned an error code"); + } + + return true; +} + /*}}}*/ + // CopyFile - Buffered copy of a file /*{{{*/ // --------------------------------------------------------------------- /* The caller is expected to set things so that failure causes erasure */ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 041aa3309..363dd041d 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -80,6 +80,7 @@ class FileFd virtual ~FileFd(); }; +bool RunScripts(const char *Cnf); bool CopyFile(FileFd &From,FileFd &To); int GetLock(string File,bool Errors = true); bool FileExists(string File); diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 667db8ff2..fe13614c5 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -16,6 +16,7 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/depcache.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/fileutl.h> #include <unistd.h> #include <stdlib.h> @@ -93,60 +94,7 @@ bool pkgDPkgPM::Remove(PkgIterator Pkg,bool Purge) each one is run with system from a forked child. */ bool pkgDPkgPM::RunScripts(const char *Cnf) { - Configuration::Item const *Opts = _config->Tree(Cnf); - if (Opts == 0 || Opts->Child == 0) - return true; - Opts = Opts->Child; - - // Fork for running the system calls - pid_t Child = ExecFork(); - - // This is the child - if (Child == 0) - { - if (chdir("/tmp/") != 0) - _exit(100); - - unsigned int Count = 1; - for (; Opts != 0; Opts = Opts->Next, Count++) - { - if (Opts->Value.empty() == true) - continue; - - if (system(Opts->Value.c_str()) != 0) - _exit(100+Count); - } - _exit(0); - } - - // Wait for the child - int Status = 0; - while (waitpid(Child,&Status,0) != Child) - { - if (errno == EINTR) - continue; - return _error->Errno("waitpid","Couldn't wait for subprocess"); - } - - // Restore sig int/quit - signal(SIGQUIT,SIG_DFL); - signal(SIGINT,SIG_DFL); - - // Check for an error code. - if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) - { - unsigned int Count = WEXITSTATUS(Status); - if (Count > 100) - { - Count -= 100; - for (; Opts != 0 && Count != 1; Opts = Opts->Next, Count--); - _error->Error("Problem executing scripts %s '%s'",Cnf,Opts->Value.c_str()); - } - - return _error->Error("Sub-process returned an error code"); - } - - return true; + RunScripts(Cnf); } /*}}}*/ // DPkgPM::SendV2Pkgs - Send version 2 package info /*{{{*/ |