diff options
author | Razvan Becheriu <razvan@isc.org> | 2021-02-18 11:04:26 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2021-02-18 18:23:57 +0100 |
commit | fb06acea1c1fbf878d618de01af1078b752c334f (patch) | |
tree | d4b59609b1996f3ac0e5ef26b4178cbd3d81708c /src/lib/asiolink | |
parent | [#899] waitForProcess must be a static function (diff) | |
download | kea-fb06acea1c1fbf878d618de01af1078b752c334f.tar.xz kea-fb06acea1c1fbf878d618de01af1078b752c334f.zip |
[#899] fixed unittests
Diffstat (limited to 'src/lib/asiolink')
-rw-r--r-- | src/lib/asiolink/process_spawn.cc | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/lib/asiolink/process_spawn.cc b/src/lib/asiolink/process_spawn.cc index 2ae989ef3c..f739f1bd6a 100644 --- a/src/lib/asiolink/process_spawn.cc +++ b/src/lib/asiolink/process_spawn.cc @@ -39,9 +39,12 @@ struct ProcessState { int status_; }; +/// @brief Defines a pointer to a ProcessState. +typedef boost::shared_ptr<ProcessState> ProcessStatePtr; + /// @brief ProcessStates container which stores a ProcessState for each process /// identified by PID. -typedef std::map<pid_t, ProcessState> ProcessStates; +typedef std::map<pid_t, ProcessStatePtr> ProcessStates; class ProcessSpawnImpl; @@ -273,7 +276,7 @@ ProcessSpawnImpl::spawn(bool dismiss) { try { lock_guard<std::mutex> lk(mutex_); store_ = true; - process_collection_[this].insert(std::pair<pid_t, ProcessState>(pid, ProcessState())); + process_collection_[this].insert(std::pair<pid_t, ProcessStatePtr>(pid, ProcessStatePtr(new ProcessState()))); } catch(...) { pthread_sigmask(SIG_SETMASK, &osset, 0); throw; @@ -293,15 +296,15 @@ ProcessSpawnImpl::isRunning(const pid_t pid) const { << "' hasn't been spawned and it status cannot be" " returned"); } - return (proc->second.running_); + return (proc->second->running_); } bool ProcessSpawnImpl::isAnyRunning() const { lock_guard<std::mutex> lk(mutex_); if (process_collection_.find(this) != process_collection_.end()) { - for (auto proc : process_collection_[this]) { - if (proc.second.running_) { + for (auto& proc : process_collection_[this]) { + if (proc.second->running_) { return (true); } } @@ -319,7 +322,7 @@ ProcessSpawnImpl::getExitStatus(const pid_t pid) const { << "' hasn't been spawned and it status cannot be" " returned"); } - return (WEXITSTATUS(proc->second.status_)); + return (WEXITSTATUS(proc->second->status_)); } char* @@ -344,14 +347,14 @@ ProcessSpawnImpl::waitForProcess(int) { if (pid <= 0) { break; } - for (auto instance : process_collection_) { - auto proc = instance.second.find(pid); + for (auto const& instance : process_collection_) { + auto const& proc = instance.second.find(pid); /// Check that the terminating process was started /// by our instance of ProcessSpawn if (proc != instance.second.end()) { // In this order please - proc->second.status_ = status; - proc->second.running_ = false; + proc->second->status_ = status; + proc->second->running_ = false; } } } |