networkservice
Linux.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_EXECUTOR_LINUX_OSAL_H__
30 #define __UTILS_COMMAND_EXECUTOR_LINUX_OSAL_H__
31 
32 #include <memory>
33 
35 
36 namespace utils::command::osal {
37 
53 class Linux : public IOsal {
54 
55 public:
56  /* Class constructor */
57  Linux();
58 
65  ~Linux() override;
66 
68  Linux(const Linux&) = delete;
69 
71  Linux& operator=(const Linux&) = delete;
72 
74  Linux(Linux&&) = delete;
75 
77  Linux& operator=(Linux&&) = delete;
78 
85  [[nodiscard]] ProcessId createProcess() const override;
86 
91  void waitChildProcess() const override;
92 
104  void executeProgram(const char* pathname,
105  char* const argv[],
106  char* const envp[]) const override;
107 
112  void reseedPRNG() const override;
113 
119  void sanitizeFiles() const override;
120 
124  void dropPrivileges() const override;
125 
126 private:
127  struct Internal;
128  std::unique_ptr<Internal> m_internal;
129 };
130 
131 }
132 
133 #endif
This class is a high level interface added to ease testability of component that use Executor...
Definition: IOsal.h:51
void dropPrivileges() const override
Permanently drop the privileges of the process.
void sanitizeFiles() const override
Close all opened file descriptors except those related to the standard streams (stdin, stdout, stderr). These are only reopened to /dev/null if not already opened.
This class is the "low level class" that implements IOsal.h.
Definition: Linux.h:53
std::unique_ptr< Internal > m_internal
Definition: Linux.h:127
ProcessId createProcess() const override
creates a new process by duplicating the calling process. It can basically be a wrapper to fork() cal...
void waitChildProcess() const override
Wait for any child process whose process group ID is equal to that of the calling process...
void reseedPRNG() const override
Initialize the Random Number Generator for a new sequence of pseudo-random integers to be returned by...
void executeProgram(const char *pathname, char *const argv[], char *const envp[]) const override
Execute the program referred to by pathname.
Linux & operator=(const Linux &)=delete
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