Kea 3.3.3
process_spawn.h
Go to the documentation of this file.
1// Copyright (C) 2015-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef PROCESS_SPAWN_H
8#define PROCESS_SPAWN_H
9
10#include <asiolink/io_service.h>
12
13#include <cstdint>
14#include <string>
15#include <unordered_set>
16#include <vector>
17
18#include <boost/noncopyable.hpp>
19#include <boost/shared_ptr.hpp>
20
21#include <sys/types.h>
22
23namespace isc {
24namespace asiolink {
25
28public:
29 ProcessSpawnError(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) { }
31};
32
35class ProcessSpawnImpl;
36
38typedef boost::shared_ptr<ProcessSpawnImpl> ProcessSpawnImplPtr;
39
42typedef std::vector<std::string> ProcessArgs;
43
46typedef std::vector<std::string> ProcessEnvVars;
47
66class ProcessSpawn : boost::noncopyable {
67public:
68
70 enum SpawnMode : uint16_t {
71 ASYNC, // thread continues without waiting for the child to finish.
72 SYNC // thread waits for the child to finish.
73 };
74
83 ProcessSpawn(const SpawnMode mode,
84 const std::string& executable,
85 const ProcessArgs& args = ProcessArgs(),
86 const ProcessEnvVars& vars = ProcessEnvVars(),
87 const bool inherit_env = false);
88
90 ~ProcessSpawn() = default;
91
95 std::string getCommandLine(std::unordered_set<std::string> redact_args = {}) const;
96
110 pid_t spawn(bool dismiss = false);
111
121 bool isRunning(const pid_t pid) const;
122
126 bool isAnyRunning() const;
127
140 int getExitStatus(const pid_t pid) const;
141
154 void clearState(const pid_t pid);
155
160 return (io_service_);
161 }
162
167 io_service_ = io_service;
168 }
169
170private:
171
173 static isc::asiolink::IOServicePtr io_service_;
174
177};
178
179} // namespace asiolink
180} // namespace isc
181
182#endif // PROCESS_SPAWN_H
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines the logger used by the top-level component of kea-lfc.