blocxx
BLOCXX_NAMESPACE::Exec::PreExec Class Referenceabstract

This class is used to specify what spawn() should do between fork and exec. More...

#include <Exec.hpp>

Inheritance diagram for BLOCXX_NAMESPACE::Exec::PreExec:
BLOCXX_NAMESPACE::PosixExec::StandardPreExec BLOCXX_NAMESPACE::PosixExec::SystemPreExec BLOCXX_NAMESPACE::WinExec::WinStandardPreExec BLOCXX_NAMESPACE::WinExec::WinSystemPreExec

Classes

struct  DontCatch
 Use this class to allow call() to throw an exception. More...
 
struct  Error
 

Public Types

typedef ::BLOCXX_NAMESPACE::UnnamedPipepipe_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
 

Detailed Description

This class is used to specify what spawn() should do between fork and exec.

Definition at line 105 of file Exec.hpp.

Member Typedef Documentation

◆ pipe_pointer_t

Constructor & Destructor Documentation

◆ PreExec()

BLOCXX_NAMESPACE::Exec::PreExec::PreExec ( bool precompute_max_descriptors = false)

◆ ~PreExec()

BLOCXX_NAMESPACE::Exec::PreExec::~PreExec ( )
virtual

Definition at line 342 of file PosixExec.cpp.

Member Function Documentation

◆ call()

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.

Parameters
pparran 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.

References closeDescriptorsOnExec(), closePipesOnExec(), resetSignals(), setNewProcessGroup(), and setupStandardDescriptors().

◆ closeDescriptorsOnExec()

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.

References m_max_descriptors.

Referenced by call().

◆ closePipesOnExec()

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.

Parameters
pparrThe 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().

Referenced by call().

◆ keepStd()

virtual bool BLOCXX_NAMESPACE::Exec::PreExec::keepStd ( int d) const
pure virtual
Returns
True if 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.
Precondition
0 <= d < 3.

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().

◆ resetSignals()

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.

References NSIG.

Referenced by call().

◆ setNewProcessGroup()

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 call().

◆ setupStandardDescriptors()

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.

Parameters
pparrThe 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 call().

Member Data Documentation

◆ m_max_descriptors

long BLOCXX_NAMESPACE::Exec::PreExec::m_max_descriptors
protected

Definition at line 200 of file Exec.hpp.

Referenced by closeDescriptorsOnExec(), and PreExec().


The documentation for this class was generated from the following files: