Kea 3.1.3
process_spawn.h
Go to the documentation of this file.
1// Copyright (C) 2015-2025 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#include <boost/noncopyable.hpp>
13#include <string>
14#include <sys/types.h>
15#include <vector>
16#include <boost/shared_ptr.hpp>
17
18#include <unordered_set>
19
20namespace isc {
21namespace asiolink {
22
25public:
26 ProcessSpawnError(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { }
28};
29
32class ProcessSpawnImpl;
33
35typedef boost::shared_ptr<ProcessSpawnImpl> ProcessSpawnImplPtr;
36
39typedef std::vector<std::string> ProcessArgs;
40
43typedef std::vector<std::string> ProcessEnvVars;
44
63class ProcessSpawn : boost::noncopyable {
64public:
65
67 enum SpawnMode {
68 ASYNC, // thread continues without waiting for the child to finish.
69 SYNC // thread waits for the child to finish.
70 };
71
80 ProcessSpawn(const SpawnMode mode,
81 const std::string& executable,
82 const ProcessArgs& args = ProcessArgs(),
83 const ProcessEnvVars& vars = ProcessEnvVars(),
84 const bool inherit_env = false);
85
87 ~ProcessSpawn() = default;
88
92 std::string getCommandLine(std::unordered_set<std::string> redact_args = {}) const;
93
107 pid_t spawn(bool dismiss = false);
108
118 bool isRunning(const pid_t pid) const;
119
123 bool isAnyRunning() const;
124
137 int getExitStatus(const pid_t pid) const;
138
151 void clearState(const pid_t pid);
152
157 return (io_service_);
158 }
159
164 io_service_ = io_service;
165 }
166
167private:
168
170 static isc::asiolink::IOServicePtr io_service_;
171
174};
175
176} // namespace asiolink
177} // namespace isc
178
179#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.