Kea: process_spawn.h Source File

| Kea 2.2.0

process_spawn.h
Go to the documentation of this file.
1// Copyright (C) 2015-2021 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>
11#include <exceptions/exceptions.h>
12#include <boost/noncopyable.hpp>
13#include <string>
14#include <sys/types.h>
15#include <vector>
16#include <boost/shared_ptr.hpp>
17
18namespace isc {
19namespace asiolink {
20
22 class ProcessSpawnError : public Exception {
23public:
24 ProcessSpawnError(const char* file, size_t line, const char* what) :
25 isc::Exception(file, line, what) { };
26};
27
30class ProcessSpawnImpl;
31
33 typedef boost::shared_ptr<ProcessSpawnImpl> ProcessSpawnImplPtr;
34
37 typedef std::vector<std::string> ProcessArgs;
38
41 typedef std::vector<std::string> ProcessEnvVars;
42
61 class ProcessSpawn : boost::noncopyable {
62public:
63
70 ProcessSpawn(isc::asiolink::IOServicePtr io_service,
71 const std::string& executable,
72 const ProcessArgs& args = ProcessArgs(),
73 const ProcessEnvVars& vars = ProcessEnvVars());
74
76 ~ProcessSpawn() = default;
77
79 std::string getCommandLine() const;
80
94 pid_t spawn(bool dismiss = false);
95
105 bool isRunning(const pid_t pid) const;
106
110 bool isAnyRunning() const;
111
124 int getExitStatus(const pid_t pid) const;
125
138 void clearState(const pid_t pid);
139
140private:
141
143 ProcessSpawnImplPtr impl_;
144};
145
146} // namespace asiolink
147} // namespace isc
148
149#endif // PROCESS_SPAWN_H
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::asiolink::ProcessSpawnError
Exception thrown when error occurs during spawning a process.
Definition: process_spawn.h:22
isc::asiolink::ProcessSpawnError::ProcessSpawnError
ProcessSpawnError(const char *file, size_t line, const char *what)
Definition: process_spawn.h:24
isc::asiolink::ProcessSpawn
Utility class for spawning new processes.
Definition: process_spawn.h:61
isc::asiolink::ProcessSpawn::ProcessSpawn
ProcessSpawn(isc::asiolink::IOServicePtr io_service, const std::string &executable, const ProcessArgs &args=ProcessArgs(), const ProcessEnvVars &vars=ProcessEnvVars())
Constructor.
Definition: process_spawn.cc:410
isc::asiolink::ProcessSpawn::isAnyRunning
bool isAnyRunning() const
Checks if any of the spawned processes is still running.
Definition: process_spawn.cc:433
isc::asiolink::ProcessSpawn::getExitStatus
int getExitStatus(const pid_t pid) const
Returns exit status of the process.
Definition: process_spawn.cc:438
isc::asiolink::ProcessSpawn::clearState
void clearState(const pid_t pid)
Removes the status of the process with a specified PID.
Definition: process_spawn.cc:443
isc::asiolink::ProcessSpawn::isRunning
bool isRunning(const pid_t pid) const
Checks if the process is still running.
Definition: process_spawn.cc:428
isc::asiolink::ProcessSpawn::getCommandLine
std::string getCommandLine() const
Returns full command line, including arguments, for the process.
Definition: process_spawn.cc:418
isc::asiolink::ProcessSpawn::~ProcessSpawn
~ProcessSpawn()=default
Destructor.
isc::asiolink::ProcessSpawn::spawn
pid_t spawn(bool dismiss=false)
Spawn the new process.
Definition: process_spawn.cc:423
exceptions.h
io_service.h
asiolink
A wrapper interface for the ASIO library.
isc::asiolink::ProcessArgs
std::vector< std::string > ProcessArgs
Type of the container holding arguments of the executable being run as a background process.
Definition: process_spawn.h:37
isc::asiolink::ProcessEnvVars
std::vector< std::string > ProcessEnvVars
Type of the container holding environment variables of the executable being run as a background proce...
Definition: process_spawn.h:41
isc::asiolink::ProcessSpawnImplPtr
boost::shared_ptr< ProcessSpawnImpl > ProcessSpawnImplPtr
Pointer to a ProcessSpawnImpl class.
Definition: process_spawn.h:30
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition: io_service.h:110
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143