Kea: process_spawn.h Source File

| Kea 1.5.0

process_spawn.h
Go to the documentation of this file.
1 // Copyright (C) 2015 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 <exceptions/exceptions.h>
11 #include <boost/noncopyable.hpp>
12 #include <string>
13 #include <sys/types.h>
14 #include <vector>
15
16 namespace isc {
17 namespace util {
18
20 class ProcessSpawnError : public Exception {
21 public:
22 ProcessSpawnError(const char* file, size_t line, const char* what) :
23 isc::Exception(file, line, what) { };
24 };
25
28 class ProcessSpawnImpl;
29
32 typedef std::vector<std::string> ProcessArgs;
33
59
60 class ProcessSpawn : boost::noncopyable {
61 public:
62
67 ProcessSpawn(const std::string& executable,
68 const ProcessArgs& args = ProcessArgs());
69
71 ~ProcessSpawn();
72
74 std::string getCommandLine() const;
75
87 pid_t spawn();
88
98 bool isRunning(const pid_t pid) const;
99
103 bool isAnyRunning() const;
104
117 int getExitStatus(const pid_t pid) const;
118
131 void clearState(const pid_t pid);
132
133 private:
134
136 ProcessSpawnImpl* impl_;
137
138 };
139
140 }
141 }
142
143 #endif // PROCESS_SPAWN_H
isc::util::ProcessSpawn::clearState
void clearState(const pid_t pid)
Removes the status of the process with a specified PID.
Definition: process_spawn.cc:366
isc::util::ProcessSpawn
Utility class for spawning new processes.
Definition: process_spawn.h:60
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::util::ProcessSpawn::getExitStatus
int getExitStatus(const pid_t pid) const
Returns exit status of the process.
Definition: process_spawn.cc:361
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::util::ProcessSpawnImpl
Implementation of the ProcessSpawn class.
Definition: process_spawn.cc:52
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::util::ProcessSpawn::spawn
pid_t spawn()
Spawn the new process.
Definition: process_spawn.cc:346
isc::util::ProcessSpawn::isAnyRunning
bool isAnyRunning() const
Checks if any of the spawned processes is still running.
Definition: process_spawn.cc:356
isc::util::ProcessSpawnError::ProcessSpawnError
ProcessSpawnError(const char *file, size_t line, const char *what)
Definition: process_spawn.h:22
isc::util::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:28
exceptions.h
isc::util::ProcessSpawnError
Exception thrown when error occurs during spawning a process.
Definition: process_spawn.h:20
isc::util::ProcessSpawn::~ProcessSpawn
~ProcessSpawn()
Destructor.
Definition: process_spawn.cc:336
isc::util::ProcessSpawn::getCommandLine
std::string getCommandLine() const
Returns full command line, including arguments, for the process.
Definition: process_spawn.cc:341
isc::util::ProcessSpawn::ProcessSpawn
ProcessSpawn(const std::string &executable, const ProcessArgs &args=ProcessArgs())
Constructor.
Definition: process_spawn.cc:331
isc::util::ProcessSpawn::isRunning
bool isRunning(const pid_t pid) const
Checks if the process is still running.
Definition: process_spawn.cc:351