blocxx
|
This class is used to specify what spawn() should do between fork and exec. More...
#include <Exec.hpp>
Classes | |
struct | DontCatch |
Use this class to allow call() to throw an exception. More... | |
struct | Error |
Public Types | |
typedef ::BLOCXX_NAMESPACE::UnnamedPipe * | pipe_pointer_t |
Public Member Functions | |
PreExec (bool precompute_max_descriptors=false) | |
virtual | ~PreExec () |
virtual bool | keepStd (int d) const =0 |
virtual void | call (pipe_pointer_t const pparr[])=0 |
This function is called between fork and exec in the spawn() function. | |
void | closeDescriptorsOnExec (std::vector< bool > const &keep) |
For calling from PreExec::call . | |
Static Public Member Functions | |
static void | resetSignals () |
For calling from PreExec::call . | |
static void | closePipesOnExec (pipe_pointer_t const pparr[]) |
For calling from PreExec::call . | |
static void | setupStandardDescriptors (pipe_pointer_t const pparr[]) |
For calling from PreExec::call . | |
static void | setNewProcessGroup () |
For calling from PreExec::call(). | |
Protected Attributes | |
long | m_max_descriptors |
This class is used to specify what spawn() should do between fork and exec.
BLOCXX_NAMESPACE::Exec::PreExec::PreExec | ( | bool | precompute_max_descriptors = false | ) |
Definition at line 337 of file PosixExec.cpp.
BLOCXX_NAMESPACE::Exec::PreExec::~PreExec | ( | ) | [virtual] |
Definition at line 342 of file PosixExec.cpp.
virtual void BLOCXX_NAMESPACE::Exec::PreExec::call | ( | pipe_pointer_t const | pparr[] | ) | [pure virtual] |
This function is called between fork
and exec
in the spawn()
function.
It must not allocate memory unless you can guarantee that there is only one thread running -- on some platforms allocating memory between fork and exec when there were other threads running can result in a deadlock.
Any exception thrown of type PreExec::Error
or derived from std::exception
is reported in full back to the parent; any exception derived from PreExec::DontCatch
is allowed to propagate out of Exec::spawn
; and any other type of exception is reported as an unknown exception.
pparr | an array pointer that can be passed to the static functions close_pipes_on_exec() and setup_std_descriptors() . It includes pipes for each of the standard descriptors, plus any additional pipes used by Exec::spawn for communicating between child and parent before the execve occurs. |
Implemented in BLOCXX_NAMESPACE::PosixExec::StandardPreExec, BLOCXX_NAMESPACE::PosixExec::SystemPreExec, BLOCXX_NAMESPACE::WinExec::WinStandardPreExec, and BLOCXX_NAMESPACE::WinExec::WinSystemPreExec.
void BLOCXX_NAMESPACE::Exec::PreExec::closeDescriptorsOnExec | ( | std::vector< bool > const & | keep | ) |
For calling from PreExec::call
.
Sets every descriptor to close-on-exec, with the exception of the standard descriptors 0, 1, and 2, and those descriptors d for which d < keep.size() and keep[d] is true.
Definition at line 288 of file PosixExec.cpp.
Referenced by BLOCXX_NAMESPACE::PosixExec::SystemPreExec::call(), and BLOCXX_NAMESPACE::PosixExec::StandardPreExec::call().
void BLOCXX_NAMESPACE::Exec::PreExec::closePipesOnExec | ( | pipe_pointer_t const | pparr[] | ) | [static] |
For calling from PreExec::call
.
Sets all the pipe descriptors in pparr to close-on-exec.
pparr | The pparr parameter passed to PreExec::call . |
Definition at line 318 of file PosixExec.cpp.
References BLOCXX_NAMESPACE::Exec::Impl::BLOCXX_NPIPE, BLOCXX_NAMESPACE::UnnamedPipe::getInputDescriptor(), and BLOCXX_NAMESPACE::UnnamedPipe::getOutputDescriptor().
virtual bool BLOCXX_NAMESPACE::Exec::PreExec::keepStd | ( | int | d | ) | const [pure virtual] |
Process
object returned by spawn()
should contain one end of a pipe connected to standard descriptor d for the child process. False if standard descriptor d of child should be connected to /dev/null
.Implemented in BLOCXX_NAMESPACE::PosixExec::StandardPreExec, BLOCXX_NAMESPACE::PosixExec::SystemPreExec, BLOCXX_NAMESPACE::WinExec::WinStandardPreExec, and BLOCXX_NAMESPACE::WinExec::WinSystemPreExec.
Referenced by BLOCXX_NAMESPACE::PosixExec::spawnImpl().
void BLOCXX_NAMESPACE::Exec::PreExec::resetSignals | ( | ) | [static] |
For calling from PreExec::call
.
Resets all signals to their default actions.
Definition at line 241 of file PosixExec.cpp.
Referenced by BLOCXX_NAMESPACE::PosixExec::SystemPreExec::call(), and BLOCXX_NAMESPACE::PosixExec::StandardPreExec::call().
void BLOCXX_NAMESPACE::Exec::PreExec::setNewProcessGroup | ( | ) | [static] |
For calling from PreExec::call().
Sets the process group ID of the process to be a new process group. In POSIX terms, setpgid(0, 0) is called. This allows signals to be send to the new process group, which will include the process any any descendents which have not joined a new process group.
Definition at line 331 of file PosixExec.cpp.
References BLOCXX_ASSERT.
Referenced by BLOCXX_NAMESPACE::PosixExec::SystemPreExec::call(), and BLOCXX_NAMESPACE::PosixExec::StandardPreExec::call().
void BLOCXX_NAMESPACE::Exec::PreExec::setupStandardDescriptors | ( | pipe_pointer_t const | pparr[] | ) | [static] |
For calling from PreExec::call
.
Connects standard descriptors to the appropriate pipes, or opens them to /dev/null
, as appropriate.
pparr | The pparr parameter passed to PreExec::call . |
Definition at line 300 of file PosixExec.cpp.
References _PATH_DEVNULL, BLOCXX_NAMESPACE::Exec::Impl::BLOCXX_IN, BLOCXX_NAMESPACE::PosixUnnamedPipe::getInputHandle(), and BLOCXX_NAMESPACE::PosixUnnamedPipe::getOutputHandle().
Referenced by BLOCXX_NAMESPACE::PosixExec::StandardPreExec::call().
long BLOCXX_NAMESPACE::Exec::PreExec::m_max_descriptors [protected] |