networkservice
Public Types | Public Member Functions | List of all members
utils::command::osal::IOsal Interface Referenceabstract

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"

Inheritance diagram for utils::command::osal::IOsal:
Inheritance graph
[legend]

Public Types

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

Public Member Functions

 IOsal ()=default
 
virtual ~IOsal ()=default
 
 IOsal (const IOsal &)=delete
 
IOsaloperator= (const IOsal &)=delete
 
 IOsal (IOsal &&)=delete
 
IOsaloperator= (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...
 

Detailed Description

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

Member Enumeration Documentation

◆ 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

Constructor & Destructor Documentation

◆ IOsal() [1/3]

utils::command::osal::IOsal::IOsal ( )
default

Class constructor

◆ ~IOsal()

virtual utils::command::osal::IOsal::~IOsal ( )
virtualdefault

Class destructor

◆ IOsal() [2/3]

utils::command::osal::IOsal::IOsal ( const IOsal )
delete

Class copy constructor

◆ IOsal() [3/3]

utils::command::osal::IOsal::IOsal ( IOsal &&  )
delete

Class move constructor

Member Function Documentation

◆ 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

Permanently drop the privileges of the process.

Implemented in utils::command::osal::Linux.

◆ 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
pathnameEither a binary executable, or a script starting with a line of the form: "#! interpreter [optional-arg]"
argvAn 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.
envpAn 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: