Просмотр исходного кода

Working apt-get source build stuff
Author: jgg
Date: 1999-04-20 05:02:09 GMT
Working apt-get source build stuff

Arch Librarian лет назад: 22
Родитель
Сommit
54676e1a82
6 измененных файлов с 107 добавлено и 94 удалено
  1. 2 18
      apt-pkg/acquire-worker.cc
  2. 3 11
      apt-pkg/contrib/cdromutl.cc
  3. 36 1
      apt-pkg/contrib/fileutl.cc
  4. 2 1
      apt-pkg/contrib/fileutl.h
  5. 3 29
      apt-pkg/deb/dpkgpm.cc
  6. 61 34
      cmdline/apt-get.cc

+ 2 - 18
apt-pkg/acquire-worker.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire-worker.cc,v 1.20 1999/03/16 00:43:55 jgg Exp $
+// $Id: acquire-worker.cc,v 1.21 1999/04/20 05:02:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire Worker 
    Acquire Worker 
@@ -115,12 +115,7 @@ bool pkgAcquire::Worker::Start()
       SetCloseExec(Pipes[0],true);
       SetCloseExec(Pipes[0],true);
    
    
    // Fork off the process
    // Fork off the process
-   Process = fork();
-   if (Process < 0)
-   {
-      cerr << "FATAL -> Failed to fork." << endl;
-      exit(100);
-   }
+   Process = ExecFork();
 
 
    // Spawn the subprocess
    // Spawn the subprocess
    if (Process == 0)
    if (Process == 0)
@@ -132,17 +127,6 @@ bool pkgAcquire::Worker::Start()
       SetCloseExec(STDOUT_FILENO,false);
       SetCloseExec(STDOUT_FILENO,false);
       SetCloseExec(STDIN_FILENO,false);      
       SetCloseExec(STDIN_FILENO,false);      
       SetCloseExec(STDERR_FILENO,false);
       SetCloseExec(STDERR_FILENO,false);
-
-      signal(SIGPIPE,SIG_DFL);
-      signal(SIGQUIT,SIG_DFL);
-      signal(SIGINT,SIG_DFL);
-      signal(SIGWINCH,SIG_DFL);
-      signal(SIGCONT,SIG_DFL);
-      signal(SIGTSTP,SIG_DFL);
-      
-      // Close all of our FDs - just in case
-      for (int K = 3; K != 40; K++)
-	 fcntl(K,F_SETFD,FD_CLOEXEC);
       
       
       const char *Args[2];
       const char *Args[2];
       Args[0] = Method.c_str();
       Args[0] = Method.c_str();

+ 3 - 11
apt-pkg/contrib/cdromutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: cdromutl.cc,v 1.3 1999/04/03 01:05:24 jgg Exp $
+// $Id: cdromutl.cc,v 1.4 1999/04/20 05:02:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    CDROM Utilities - Some functions to manipulate CDROM mounts.
    CDROM Utilities - Some functions to manipulate CDROM mounts.
@@ -66,16 +66,12 @@ bool UnmountCdrom(string Path)
    if (IsMounted(Path) == false)
    if (IsMounted(Path) == false)
       return true;
       return true;
    
    
-   int Child = fork();
-   if (Child < -1)
-      return _error->Errno("fork","Failed to fork");
+   int Child = ExecFork();
 
 
    // The child
    // The child
    if (Child == 0)
    if (Child == 0)
    {
    {
       // Make all the fds /dev/null
       // Make all the fds /dev/null
-      for (int I = 0; I != 10; I++)
-	 close(I);
       for (int I = 0; I != 3; I++)
       for (int I = 0; I != 3; I++)
 	 dup2(open("/dev/null",O_RDWR),I);
 	 dup2(open("/dev/null",O_RDWR),I);
 
 
@@ -119,16 +115,12 @@ bool MountCdrom(string Path)
    if (IsMounted(Path) == true)
    if (IsMounted(Path) == true)
       return true;
       return true;
    
    
-   int Child = fork();
-   if (Child < -1)
-      return _error->Errno("fork","Failed to fork");
+   int Child = ExecFork();
 
 
    // The child
    // The child
    if (Child == 0)
    if (Child == 0)
    {
    {
       // Make all the fds /dev/null
       // Make all the fds /dev/null
-      for (int I = 0; I != 10; I++)
-	 close(I);      
       for (int I = 0; I != 3; I++)
       for (int I = 0; I != 3; I++)
 	 dup2(open("/dev/null",O_RDWR),I);
 	 dup2(open("/dev/null",O_RDWR),I);
       
       

+ 36 - 1
apt-pkg/contrib/fileutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.cc,v 1.26 1999/03/21 07:24:14 jgg Exp $
+// $Id: fileutl.cc,v 1.27 1999/04/20 05:02:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -25,6 +25,7 @@
 #include <sys/fcntl.h>
 #include <sys/fcntl.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/time.h>
+#include <signal.h>
 #include <errno.h>
 #include <errno.h>
 									/*}}}*/
 									/*}}}*/
 
 
@@ -214,6 +215,40 @@ bool WaitFd(int Fd,bool write,unsigned long timeout)
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// ExecFork - Magical fork that sanitizes the context before execing	/*{{{*/
+// ---------------------------------------------------------------------
+/* This is used if you want to cleanse the environment for the forked 
+   child, it fixes up the important signals and nukes all of the fds,
+   otherwise acts like normal fork. */
+int ExecFork()
+{
+   // Fork off the process
+   pid_t Process = fork();
+   if (Process < 0)
+   {
+      cerr << "FATAL -> Failed to fork." << endl;
+      exit(100);
+   }
+
+   // Spawn the subprocess
+   if (Process == 0)
+   {
+      // Setup the signals
+      signal(SIGPIPE,SIG_DFL);
+      signal(SIGQUIT,SIG_DFL);
+      signal(SIGINT,SIG_DFL);
+      signal(SIGWINCH,SIG_DFL);
+      signal(SIGCONT,SIG_DFL);
+      signal(SIGTSTP,SIG_DFL);
+      
+      // Close all of our FDs - just in case
+      for (int K = 3; K != 40; K++)
+	 fcntl(K,F_SETFD,FD_CLOEXEC);
+   }
+   
+   return Process;
+}
+									/*}}}*/
 
 
 // FileFd::FileFd - Open a file						/*{{{*/
 // FileFd::FileFd - Open a file						/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------

+ 2 - 1
apt-pkg/contrib/fileutl.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.h,v 1.17 1999/04/07 05:35:55 jgg Exp $
+// $Id: fileutl.h,v 1.18 1999/04/20 05:02:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -69,6 +69,7 @@ string SafeGetCWD();
 void SetCloseExec(int Fd,bool Close);
 void SetCloseExec(int Fd,bool Close);
 void SetNonBlock(int Fd,bool Block);
 void SetNonBlock(int Fd,bool Block);
 bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
 bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
+int ExecFork();
 
 
 // File string manipulators
 // File string manipulators
 string flNotDir(string File);
 string flNotDir(string File);

+ 3 - 29
apt-pkg/deb/dpkgpm.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: dpkgpm.cc,v 1.8 1999/03/05 19:36:49 jgg Exp $
+// $Id: dpkgpm.cc,v 1.9 1999/04/20 05:02:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    DPKG Package Manager - Provide an interface to dpkg
    DPKG Package Manager - Provide an interface to dpkg
@@ -86,27 +86,14 @@ bool pkgDPkgPM::RunScripts(const char *Cnf)
    Opts = Opts->Child;
    Opts = Opts->Child;
 
 
    // Fork for running the system calls
    // Fork for running the system calls
-   pid_t Child = fork();
-   if (Child < 0)
-      return _error->Errno("fork","Could't fork");
+   pid_t Child = ExecFork();
    
    
    // This is the child
    // This is the child
    if (Child == 0)
    if (Child == 0)
    {
    {
-      signal(SIGPIPE,SIG_DFL);
-      signal(SIGQUIT,SIG_DFL);
-      signal(SIGINT,SIG_DFL);
-      signal(SIGWINCH,SIG_DFL);
-      signal(SIGCONT,SIG_DFL);
-      signal(SIGTSTP,SIG_DFL);
-      
       if (chdir("/tmp/") != 0)
       if (chdir("/tmp/") != 0)
 	 _exit(100);
 	 _exit(100);
 	 
 	 
-      // Close all of our FDs - just in case
-      for (int K = 3; K != 40; K++)
-	 fcntl(K,F_SETFD,FD_CLOEXEC);
-
       unsigned int Count = 1;
       unsigned int Count = 1;
       for (; Opts != 0; Opts = Opts->Next, Count++)
       for (; Opts != 0; Opts = Opts->Next, Count++)
       {
       {
@@ -250,27 +237,14 @@ bool pkgDPkgPM::Go()
       signal(SIGINT,SIG_IGN);
       signal(SIGINT,SIG_IGN);
 		     
 		     
       // Fork dpkg
       // Fork dpkg
-      pid_t Child = fork();
-      if (Child < 0)
-	 return _error->Errno("fork","Could't fork");
+      pid_t Child = ExecFork();
             
             
       // This is the child
       // This is the child
       if (Child == 0)
       if (Child == 0)
       {
       {
-	 signal(SIGPIPE,SIG_DFL);
-	 signal(SIGQUIT,SIG_DFL);
-	 signal(SIGINT,SIG_DFL);
-	 signal(SIGWINCH,SIG_DFL);
-	 signal(SIGCONT,SIG_DFL);
-	 signal(SIGTSTP,SIG_DFL);
-	 
 	 if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
 	 if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0)
 	    _exit(100);
 	    _exit(100);
 	 
 	 
-	 // Close all of our FDs - just in case
-	 for (int K = 3; K != 40; K++)
-	    fcntl(K,F_SETFD,FD_CLOEXEC);
-
 	 int Flags,dummy;
 	 int Flags,dummy;
 	 if ((Flags = fcntl(STDIN_FILENO,F_GETFL,dummy)) < 0)
 	 if ((Flags = fcntl(STDIN_FILENO,F_GETFL,dummy)) < 0)
 	    _exit(100);
 	    _exit(100);

+ 61 - 34
cmdline/apt-get.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: apt-get.cc,v 1.54 1999/04/19 06:03:09 jgg Exp $
+// $Id: apt-get.cc,v 1.55 1999/04/20 05:02:09 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    apt-get - Cover for dpkg
    apt-get - Cover for dpkg
@@ -51,6 +51,7 @@
 #include <signal.h>
 #include <signal.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <sys/wait.h>
 									/*}}}*/
 									/*}}}*/
 
 
 ostream c0out;
 ostream c0out;
@@ -1214,42 +1215,68 @@ bool DoSource(CommandLine &CmdL)
       return true;
       return true;
    
    
    // Unpack the sources
    // Unpack the sources
-   for (unsigned I = 0; I != J; I++)
+   pid_t Process = ExecFork();
+   
+   if (Process == 0)
    {
    {
-      string Dir = Dsc[I].Package + '-' + pkgBaseVersion(Dsc[I].Version.c_str());
-    
-      // See if the package is already unpacked
-      struct stat Stat;
-      if (stat(Dir.c_str(),&Stat) == 0 &&
-	  S_ISDIR(Stat.st_mode) != 0)
-      {
-	 c0out << "Skipping unpack of already unpacked source in " << Dir << endl;
-      }
-      else
+      for (unsigned I = 0; I != J; I++)
       {
       {
-	 // Call dpkg-source
-	 char S[500];
-	 snprintf(S,sizeof(S),"%s -x %s",
-		  _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
-		  Dsc[I].Dsc.c_str());
-	 if (system(S) != 0)
-	    return _error->Error("Unpack command '%s' failed.",S);
-      }
-  
-      // Try to compile it with dpkg-buildpackage
-      if (_config->FindB("APT::Get::Compile",false) == true)
-      {
-	 // Call dpkg-buildpackage
-	 char S[500];
-	 snprintf(S,sizeof(S),"cd %s && %s %s",
-		  Dir.c_str(),
-		  _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
-		  _config->Find("DPkg::Build-Options","-b -uc").c_str());
+	 string Dir = Dsc[I].Package + '-' + pkgBaseVersion(Dsc[I].Version.c_str());
 	 
 	 
-	 if (system(S) != 0)
-	    return _error->Error("Build command '%s' failed.",S);
-      }      
-   }   
+	 // See if the package is already unpacked
+	 struct stat Stat;
+	 if (stat(Dir.c_str(),&Stat) == 0 &&
+	     S_ISDIR(Stat.st_mode) != 0)
+	 {
+	    c0out << "Skipping unpack of already unpacked source in " << Dir << endl;
+	 }
+	 else
+	 {
+	    // Call dpkg-source
+	    char S[500];
+	    snprintf(S,sizeof(S),"%s -x %s",
+		     _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
+		     Dsc[I].Dsc.c_str());
+	    if (system(S) != 0)
+	    {
+	       cerr << "Unpack command '" << S << "' failed." << endl;
+	       _exit(1);
+	    }	    
+	 }
+	 
+	 // Try to compile it with dpkg-buildpackage
+	 if (_config->FindB("APT::Get::Compile",false) == true)
+	 {
+	    // Call dpkg-buildpackage
+	    char S[500];
+	    snprintf(S,sizeof(S),"cd %s && %s %s",
+		     Dir.c_str(),
+		     _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
+		     _config->Find("DPkg::Build-Options","-b -uc").c_str());
+	    
+	    if (system(S) != 0)
+	    {
+	       cerr << "Build command '" << S << "' failed." << endl;
+	       _exit(1);
+	    }	    
+	 }      
+      }
+      
+      _exit(0);
+   }
+   
+   // Wait for the subprocess
+   int Status = 0;
+   while (waitpid(Process,&Status,0) != Process)
+   {
+      if (errno == EINTR)
+	 continue;
+      return _error->Errno("waitpid","Couldn't wait for subprocess");
+   }
+
+   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
+      return _error->Error("Child process failed");
+   
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/