]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3669] Added support for ProcessSpawn spawning more processes.
authorMarcin Siodelski <marcin@isc.org>
Thu, 5 Feb 2015 14:58:28 +0000 (15:58 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 5 Feb 2015 14:58:28 +0000 (15:58 +0100)
src/lib/util/process_spawn.cc
src/lib/util/process_spawn.h

index eb6f19de55e9e5562e45606fc7afbf4d3f39e714..0986413db65aebf2f4fffb564c7bc762d80fc7f2 100644 (file)
@@ -66,6 +66,11 @@ public:
     /// @return true if the child process is running, false otherwise.
     bool isRunning(const pid_t pid) const;
 
+    /// @brief Checks if any of the spawned processes is still running.
+    ///
+    /// @return true if at least one child process is still running.
+    bool isAnyRunning() const;
+
     /// @brief Returns exit status of the process.
     ///
     /// If the process is still running, the previous status is returned
@@ -103,6 +108,7 @@ private:
     /// @brief A signal set installing a handler for SIGCHLD.
     SignalSetPtr signals_;
 
+    /// @brief A map holding the status codes of executed processes.
     std::map<pid_t, int> process_status_;
 
     /// @brief Path to an executable.
@@ -190,6 +196,17 @@ ProcessSpawnImpl::isRunning(const pid_t pid) const {
     return ((pid != 0) && (kill(pid, 0) == 0));
 }
 
+bool
+ProcessSpawnImpl::isAnyRunning() const {
+    for (std::map<pid_t, int>::const_iterator proc = process_status_.begin();
+         proc != process_status_.end(); ++proc) {
+        if (isRunning(proc->first)) {
+            return (true);
+        }
+    }
+    return (false);
+}
+
 int
 ProcessSpawnImpl::getExitStatus(const pid_t pid) const {
     std::map<pid_t, int>::const_iterator status = process_status_.find(pid);
@@ -252,6 +269,11 @@ ProcessSpawn::isRunning(const pid_t pid) const {
     return (impl_->isRunning(pid));
 }
 
+bool
+ProcessSpawn::isAnyRunning() const {
+    return (impl_->isAnyRunning());
+}
+
 int
 ProcessSpawn::getExitStatus(const pid_t pid) const {
     return (impl_->getExitStatus(pid));
index 492aa640afffefafa541447d71b2a4d7f89904ad..977fe39456c73c514107b034083abba30004b67c 100644 (file)
@@ -90,6 +90,11 @@ public:
     /// @return true if the child process is running, false otherwise.
     bool isRunning(const pid_t pid) const;
 
+    /// @brief Checks if any of the spawned processes is still running.
+    ///
+    /// @return true if at least one child process is still running.
+    bool isAnyRunning() const;
+
     /// @brief Returns exit status of the process.
     ///
     /// If the process is still running, the previous status is returned