This class is a high level interface added to ease testability of component that use Executor. It decouples Excecutor and syscalls used to handle requests thus behaving like an OS abstraction layer.
More...
#include "utils/command/executor/IOsal.h"
|
| enum | ProcessId : unsigned int { CHILD = (1u << 0u),
PARENT = (1u << 1u)
} |
| | An id to inform caller about the current process type after a new process has been created. More...
|
| |
|
| | IOsal ()=default |
| |
| virtual | ~IOsal ()=default |
| |
| | IOsal (const IOsal &)=delete |
| |
| IOsal & | operator= (const IOsal &)=delete |
| |
| | IOsal (IOsal &&)=delete |
| |
| IOsal & | operator= (IOsal &&)=delete |
| |
| virtual ProcessId | createProcess () const =0 |
| | creates a new process by duplicating the calling process. More...
|
| |
| virtual void | waitChildProcess () const =0 |
| | Wait for any child process whose process group ID is equal to that of the calling process. More...
|
| |
| virtual void | executeProgram (const char *pathname, char *const argv[], char *const envp[]) const =0 |
| | Execute the program referred to by pathname. More...
|
| |
| virtual void | reseedPRNG () const =0 |
| | Initialize the Random Number Generator for a new sequence of pseudo-random integers to be returned by rand() More...
|
| |
| virtual void | sanitizeFiles () const =0 |
| | Close all opened file descriptors except those related to the standard streams (stdin, stdout, stderr). These are reopened to /dev/null if not already opened. More...
|
| |
| virtual void | dropPrivileges () const =0 |
| | Permanently drop the privileges of the process. More...
|
| |
This class is a high level interface added to ease testability of component that use Executor. It decouples Excecutor and syscalls used to handle requests thus behaving like an OS abstraction layer.
- Note
- Copy contructor, copy-assignment operator, move constructor and move-assignment operator are defined to be compliant with the "Rule of five"
- See also
- https://en.cppreference.com/w/cpp/language/rule_of_three
- Author
- Boubacar DIENE bouba.nosp@m.car..nosp@m.diene.nosp@m.@gma.nosp@m.il.co.nosp@m.m
- Date
- May 2020
◆ ProcessId
An id to inform caller about the current process type after a new process has been created.
| Enumerator |
|---|
| CHILD | In child process
|
| PARENT | In parent process
|
◆ IOsal() [1/3]
| utils::command::osal::IOsal::IOsal |
( |
| ) |
|
|
default |
◆ ~IOsal()
| virtual utils::command::osal::IOsal::~IOsal |
( |
| ) |
|
|
virtualdefault |
◆ IOsal() [2/3]
| utils::command::osal::IOsal::IOsal |
( |
const IOsal & |
| ) |
|
|
delete |
◆ IOsal() [3/3]
| utils::command::osal::IOsal::IOsal |
( |
IOsal && |
| ) |
|
|
delete |
◆ createProcess()
| virtual ProcessId utils::command::osal::IOsal::createProcess |
( |
| ) |
const |
|
pure virtual |
creates a new process by duplicating the calling process.
It can basically be a wrapper of fork() call in linux.
- Returns
- An id of type ProcessId
Implemented in utils::command::osal::Linux.
◆ dropPrivileges()
| virtual void utils::command::osal::IOsal::dropPrivileges |
( |
| ) |
const |
|
pure virtual |
◆ executeProgram()
| virtual void utils::command::osal::IOsal::executeProgram |
( |
const char * |
pathname, |
|
|
char *const |
argv[], |
|
|
char *const |
envp[] |
|
) |
| const |
|
pure virtual |
Execute the program referred to by pathname.
It can basically be a wrapper of a exec()-like function. It is expected it does not return unless an error is encountered.
- Parameters
-
| pathname | Either a binary executable, or a script starting with a line of the form: "#! interpreter [optional-arg]" |
| argv | An array of argument strings passed to the new program. By convention, the first of these strings should contain the filename associated with the file being executed. |
| envp | An array of strings of the form key=value, which are passed as environment to the new program. |
Implemented in utils::command::osal::Linux.
◆ operator=() [1/2]
| IOsal& utils::command::osal::IOsal::operator= |
( |
const IOsal & |
| ) |
|
|
delete |
Class copy-assignment operator
◆ operator=() [2/2]
| IOsal& utils::command::osal::IOsal::operator= |
( |
IOsal && |
| ) |
|
|
delete |
Class move-assignment operator
◆ reseedPRNG()
| virtual void utils::command::osal::IOsal::reseedPRNG |
( |
| ) |
const |
|
pure virtual |
Initialize the Random Number Generator for a new sequence of pseudo-random integers to be returned by rand()
Implemented in utils::command::osal::Linux.
◆ sanitizeFiles()
| virtual void utils::command::osal::IOsal::sanitizeFiles |
( |
| ) |
const |
|
pure virtual |
Close all opened file descriptors except those related to the standard streams (stdin, stdout, stderr). These are reopened to /dev/null if not already opened.
Implemented in utils::command::osal::Linux.
◆ waitChildProcess()
| virtual void utils::command::osal::IOsal::waitChildProcess |
( |
| ) |
const |
|
pure virtual |
Wait for any child process whose process group ID is equal to that of the calling process.
It can basically be a wrapper of waitpid() call in linux with a pid equal to 0.
- Note
- This method raises an exception when the child process failed
Implemented in utils::command::osal::Linux.
The documentation for this interface was generated from the following file:
- /workdir/src/utils/command/executor/IOsal.h