]> git.saurik.com Git - apt.git/commitdiff
Joey Hess's patch
authorArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:54:26 +0000 (16:54 +0000)
committerArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:54:26 +0000 (16:54 +0000)
Author: jgg
Date: 1999-07-30 06:15:14 GMT
Joey Hess's patch

apt-pkg/deb/dpkgpm.cc
apt-pkg/deb/dpkgpm.h

index 7645929dbd1383d0c27099116e0886f390127c84..e68dfdc4472518a73ff8d79f07054edfaebb2be3 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: dpkgpm.cc,v 1.12 1999/07/26 17:46:08 jgg Exp $
+// $Id: dpkgpm.cc,v 1.13 1999/07/30 06:15:14 jgg Exp $
 /* ######################################################################
 
    DPKG Package Manager - Provide an interface to dpkg
@@ -22,6 +22,7 @@
 #include <sys/wait.h>
 #include <signal.h>
 #include <errno.h>
+#include <stdio.h>
                                                                        /*}}}*/
 
 // DPkgPM::pkgDPkgPM - Constructor                                     /*{{{*/
@@ -138,6 +139,87 @@ bool pkgDPkgPM::RunScripts(const char *Cnf)
    
    return true;
 }
+
+                                                                        /*}}}*/
+// DPkgPM::RunScriptsWithPkgs - Run scripts with package names on stdin /*{{{*/
+// ---------------------------------------------------------------------
+/* This looks for a list of scripts to run from the configuration file
+   each one is run and is fed on standard input a list of all .deb files
+   that are due to be installed. */
+bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
+{
+   Configuration::Item const *Opts = _config->Tree(Cnf);
+   if (Opts == 0 || Opts->Child == 0)
+      return true;
+   Opts = Opts->Child;
+   
+   unsigned int Count = 1;
+   for (; Opts != 0; Opts = Opts->Next, Count++)
+   {
+      if (Opts->Value.empty() == true)
+         continue;
+               
+      // Create the pipes
+      int Pipes[2];
+      if (pipe(Pipes) != 0)
+        return _error->Errno("pipe","Failed to create IPC pipe to subprocess");
+      SetCloseExec(Pipes[0],true);
+      SetCloseExec(Pipes[1],true);
+      
+      // Purified Fork for running the script
+      pid_t Process = ExecFork();      
+      if (Process == 0)
+      {
+        // Setup the FDs
+        dup2(Pipes[0],STDIN_FILENO);
+        SetCloseExec(STDOUT_FILENO,false);
+        SetCloseExec(STDIN_FILENO,false);      
+        SetCloseExec(STDERR_FILENO,false);
+        
+        const char *Args[5];
+        Args[0] = "/bin/sh";
+        Args[1] = "/bin/sh";
+        Args[2] = "-c";
+        Args[3] = Opts->Value.c_str();
+        Args[4] = 0;
+        execv(Args[0],(char **)Args);
+        _exit(100);
+      }
+      close(Pipes[0]);
+      FileFd Fd(Pipes[1]);
+
+      // Feed it the filenames.
+      for (vector<Item>::iterator I = List.begin(); I != List.end();)
+      {
+        // Only deal with packages to be installed from .deb
+        if (I->Op != Item::Install)
+           continue;
+
+        // No errors here..
+        if (I->File[0] != '/')
+           continue;
+        
+        /* Feed the filename of each package that is pending install
+           into the pipe. */
+        if (Fd.Write(I->File.begin(),I->File.length()) == false || 
+            Fd.Write("\n",1) == false)
+        {
+           kill(Process,SIGINT);           
+           Fd.Close();   
+           ExecWait(Process,Opts->Value.c_str(),true);
+           return false;
+        }          
+      }
+      Fd.Close();
+      
+      // Clean up the sub process
+      if (ExecWait(Process,Opts->Value.c_str()) == false)
+        return false;
+   }
+
+   return true;
+}
+
                                                                        /*}}}*/
 // DPkgPM::Go - Run the sequence                                       /*{{{*/
 // ---------------------------------------------------------------------
@@ -146,7 +228,10 @@ bool pkgDPkgPM::Go()
 {
    if (RunScripts("DPkg::Pre-Invoke") == false)
       return false;
-   
+
+   if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false)
+      return false;
+
    for (vector<Item>::iterator I = List.begin(); I != List.end();)
    {
       vector<Item>::iterator J = I;
index e8ffe7bb4f7b9bd9866fc69b4ba882446b9a583f..0cc32f731488b9e034bf7e5bb03305ac9234a36e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: dpkgpm.h,v 1.5 1999/07/09 04:11:34 jgg Exp $
+// $Id: dpkgpm.h,v 1.6 1999/07/30 06:15:14 jgg Exp $
 /* ######################################################################
 
    DPKG Package Manager - Provide an interface to dpkg
@@ -35,6 +35,7 @@ class pkgDPkgPM : public pkgPackageManager
 
    // Helpers
    bool RunScripts(const char *Cnf);
+   bool RunScriptsWithPkgs(const char *Cnf);
    
    // The Actuall installation implementation
    virtual bool Install(PkgIterator Pkg,string File);