summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:53:38 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:53:38 +0000
commit54676e1a82f400e37879bc931b6db0c13b8ebb3f (patch)
treecc1a3db8623e9236855361403c5bc805ae6a42f5 /apt-pkg/contrib
parentfb0ee66e0bc8a2ae176d3b10da49fcf31c66b838 (diff)
Working apt-get source build stuff
Author: jgg Date: 1999-04-20 05:02:09 GMT Working apt-get source build stuff
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc14
-rw-r--r--apt-pkg/contrib/fileutl.cc37
-rw-r--r--apt-pkg/contrib/fileutl.h3
3 files changed, 41 insertions, 13 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index c24970553..a12c9d790 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// 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.
@@ -66,16 +66,12 @@ bool UnmountCdrom(string Path)
if (IsMounted(Path) == false)
return true;
- int Child = fork();
- if (Child < -1)
- return _error->Errno("fork","Failed to fork");
+ int Child = ExecFork();
// The child
if (Child == 0)
{
// Make all the fds /dev/null
- for (int I = 0; I != 10; I++)
- close(I);
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
@@ -119,16 +115,12 @@ bool MountCdrom(string Path)
if (IsMounted(Path) == true)
return true;
- int Child = fork();
- if (Child < -1)
- return _error->Errno("fork","Failed to fork");
+ int Child = ExecFork();
// The child
if (Child == 0)
{
// Make all the fds /dev/null
- for (int I = 0; I != 10; I++)
- close(I);
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index bc1681820..43717da16 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// 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
@@ -25,6 +25,7 @@
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <signal.h>
#include <errno.h>
/*}}}*/
@@ -214,6 +215,40 @@ bool WaitFd(int Fd,bool write,unsigned long timeout)
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 /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 4a6f6516e..8a1083241 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// 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
@@ -69,6 +69,7 @@ string SafeGetCWD();
void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
+int ExecFork();
// File string manipulators
string flNotDir(string File);