Kea 2.7.5
isc::asiolink::ProcessSpawnImpl Class Reference

Implementation of the ProcessSpawn class. More...

+ Inheritance diagram for isc::asiolink::ProcessSpawnImpl:

Public Member Functions

 ProcessSpawnImpl (const ProcessSpawn::SpawnMode mode, const std::string &executable, const ProcessArgs &args, const ProcessEnvVars &vars, const bool inherit_env)
 Constructor.
 
 ~ProcessSpawnImpl ()
 Destructor.
 
void clearState (const pid_t pid)
 Removes the status of the process with a specified PID.
 
std::string getCommandLine () const
 Returns full command line, including arguments, for the process.
 
int getExitStatus (const pid_t pid) const
 Returns exit status of the process.
 
bool isAnyRunning () const
 Checks if any of the spawned processes is still running.
 
bool isRunning (const pid_t pid) const
 Checks if the process is still running.
 
pid_t spawn (bool dismiss)
 Spawn the new process.
 

Detailed Description

Implementation of the ProcessSpawn class.

This pimpl idiom is used by the ProcessSpawn in this case to avoid exposing the internals of the implementation, such as custom handling of a SIGCHLD signal, and the conversion of the arguments of the executable from the STL container to the array.

This class is made noncopyable so that we don't have attempts to make multiple copies of an object. This avoid problems with multiple copies of objects for a single global resource such as the SIGCHLD signal handler. In addition making it noncopyable keeps the static check code from flagging the lack of a copy constructor as an issue.

Definition at line 75 of file process_spawn.cc.

Constructor & Destructor Documentation

◆ ProcessSpawnImpl()

isc::asiolink::ProcessSpawnImpl::ProcessSpawnImpl ( const ProcessSpawn::SpawnMode mode,
const std::string & executable,
const ProcessArgs & args,
const ProcessEnvVars & vars,
const bool inherit_env )

Constructor.

Parameters
modespecifies synchronous or asynchronous mode.
executableA full path to the program to be executed.
argsArguments for the program to be executed.
varsEnvironment variables for the program to be executed.
inherit_envwhether the spawned process will inherit the environment before adding 'vars' on top.

Definition at line 255 of file process_spawn.cc.

References environ, and isc_throw.

◆ ~ProcessSpawnImpl()

isc::asiolink::ProcessSpawnImpl::~ProcessSpawnImpl ( )

Destructor.

Definition at line 311 of file process_spawn.cc.

Member Function Documentation

◆ clearState()

void isc::asiolink::ProcessSpawnImpl::clearState ( const pid_t pid)

Removes the status of the process with a specified PID.

This method removes the status of the process with a specified PID. If the process is still running, the status is not removed and the exception is thrown.

Parameters
pidA process pid.

Definition at line 470 of file process_spawn.cc.

References isc_throw, and isRunning().

+ Here is the call graph for this function:

◆ getCommandLine()

std::string isc::asiolink::ProcessSpawnImpl::getCommandLine ( ) const

Returns full command line, including arguments, for the process.

Definition at line 319 of file process_spawn.cc.

◆ getExitStatus()

int isc::asiolink::ProcessSpawnImpl::getExitStatus ( const pid_t pid) const

Returns exit status of the process.

If the process is still running, the previous status is returned or 0, if the process is being ran for the first time.

Parameters
pidID of the child process for which exit status should be returned.
Returns
Exit code of the process.

Definition at line 394 of file process_spawn.cc.

References isc_throw.

◆ isAnyRunning()

bool isc::asiolink::ProcessSpawnImpl::isAnyRunning ( ) const

Checks if any of the spawned processes is still running.

Returns
true if at least one child process is still running.

Definition at line 381 of file process_spawn.cc.

◆ isRunning()

bool isc::asiolink::ProcessSpawnImpl::isRunning ( const pid_t pid) const

Checks if the process is still running.

Parameters
pidID of the child processes for which state should be checked.
Returns
true if the child process is running, false otherwise.

Definition at line 370 of file process_spawn.cc.

References isc_throw.

Referenced by clearState().

◆ spawn()

pid_t isc::asiolink::ProcessSpawnImpl::spawn ( bool dismiss)

Spawn the new process.

This method forks the current process and executes the specified binary with arguments within the child process.

The child process will return EXIT_FAILURE if the method was unable to start the executable, e.g. as a result of insufficient permissions or when the executable does not exist. If the process ends successfully the EXIT_SUCCESS is returned.

Parameters
dismissThe flag which indicated if the process status can be disregarded.
Returns
PID of the spawned process.
Exceptions
ProcessSpawnErrorif forking a current process failed.

Definition at line 334 of file process_spawn.cc.

References isc::asiolink::ProcessSpawn::ASYNC, isc::asiolink::ProcessSpawn::getIOService(), isc_throw, and isc::asiolink::ProcessSpawn::SYNC.

+ Here is the call graph for this function:

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