networkservice
IOsal.h
Go to the documentation of this file.
1 //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//
2 // //
3 // MIT License //
4 // //
5 // Copyright (c) 2020 Boubacar DIENE //
6 // //
7 // This file is part of NetworkService project //
8 // //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy //
10 // of this software and associated documentation files (the "Software"), to deal //
11 // in the Software without restriction, including without limitation the rights //
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
13 // copies of the Software, and to permit persons to whom the Software is //
14 // furnished to do so, subject to the following conditions: //
15 // //
16 // The above copyright notice and this permission notice shall be included in all //
17 // copies or substantial portions of the Software. //
18 // //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //
25 // SOFTWARE. //
26 // //
27 //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//
28 
29 #ifndef __UTILS_COMMAND_IOS_ABSTRACTION_LAYER_H__
30 #define __UTILS_COMMAND_IOS_ABSTRACTION_LAYER_H__
31 
33 
51 class IOsal {
52 
53 public:
60  enum ProcessId : unsigned int {
61  CHILD = (1u << 0u),
62  PARENT = (1u << 1u)
63  };
64 
66  IOsal() = default;
67 
69  virtual ~IOsal() = default;
70 
72  IOsal(const IOsal&) = delete;
73 
75  IOsal& operator=(const IOsal&) = delete;
76 
78  IOsal(IOsal&&) = delete;
79 
81  IOsal& operator=(IOsal&&) = delete;
82 
90  [[nodiscard]] virtual ProcessId createProcess() const = 0;
91 
101  virtual void waitChildProcess() const = 0;
102 
117  virtual void executeProgram(const char* pathname,
118  char* const argv[],
119  char* const envp[]) const = 0;
120 
125  virtual void reseedPRNG() const = 0;
126 
132  virtual void sanitizeFiles() const = 0;
133 
137  virtual void dropPrivileges() const = 0;
138 };
139 
140 }
141 
142 #endif
This class is a high level interface added to ease testability of component that use Executor...
Definition: IOsal.h:51
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.
virtual void reseedPRNG() const =0
Initialize the Random Number Generator for a new sequence of pseudo-random integers to be returned by...
virtual void executeProgram(const char *pathname, char *const argv[], char *const envp[]) const =0
Execute the program referred to by pathname.
virtual void waitChildProcess() const =0
Wait for any child process whose process group ID is equal to that of the calling process...
virtual void dropPrivileges() const =0
Permanently drop the privileges of the process.
virtual ~IOsal()=default
Definition: IOsal.h:32
ProcessId
An id to inform caller about the current process type after a new process has been created...
Definition: IOsal.h:60
IOsal & operator=(const IOsal &)=delete
virtual ProcessId createProcess() const =0
creates a new process by duplicating the calling process.