/// @return Exit code of the process.
int getExitStatus(const pid_t pid) const;
+ /// @brief Removes the status of the process with a specified PID.
+ ///
+ /// This method removes the status of the process with a specified PID.
+ /// If the process is still running, the status is not removed and the
+ /// exception is thrown.
+ ///
+ /// @param pid A process pid.
+ void clearStatus(const pid_t pid);
+
private:
/// @brief Copies the argument specified as a C++ string to the new
ProcessSpawnImpl::getExitStatus(const pid_t pid) const {
std::map<pid_t, int>::const_iterator status = process_status_.find(pid);
if (status == process_status_.end()) {
- isc_throw(BadValue, "the process with the pid '" << pid
- << "' hasn't been spawned and it status cannnot be"
+ isc_throw(InvalidOperation, "the process with the pid '" << pid
+ << "' hasn't been spawned and it status cannot be"
" returned");
}
return (WEXITSTATUS(status->second));
return (false);
}
+void
+ProcessSpawnImpl::clearStatus(const pid_t pid) {
+ if (isRunning(pid)) {
+ isc_throw(InvalidOperation, "unable to remove the status for the"
+ "process (pid: " << pid << ") which is still running");
+ }
+ process_status_.erase(pid);
+}
ProcessSpawn::ProcessSpawn(const std::string& executable,
const ProcessArgs& args)
return (impl_->getExitStatus(pid));
}
+void
+ProcessSpawn::clearStatus(const pid_t pid) {
+ return (impl_->clearStatus(pid));
+}
+
}
}
/// @return Exit code of the process.
int getExitStatus(const pid_t pid) const;
+ /// @brief Removes the status of the process with a specified PID.
+ ///
+ /// This method removes the status of the process with a specified PID.
+ /// If the process is still running, the status is not removed and the
+ /// exception is thrown.
+ ///
+ /// @param pid A process pid.
+ void clearStatus(const pid_t pid);
+
private:
/// @brief A pointer to the implementation of this class.
// This test verifies that the single ProcessSpawn object can be used
// to start two processes and that their status codes can be gathered.
+// It also checks that it is possible to clear the status of the
+// process.
TEST(ProcessSpawn, spawnTwoProcesses) {
std::vector<std::string> args;
args.push_back("-p");
ASSERT_TRUE(waitForProcess(process, pid2, 2));
EXPECT_NE(process.getExitStatus(pid1), process.getExitStatus(pid2));
+
+ // Clear the status of the first process. An atttempt to get the status
+ // for the cleared process should result in exception. But, there should
+ // be no exception for the second process.
+ process.clearStatus(pid1);
+ EXPECT_THROW(process.getExitStatus(pid1), InvalidOperation);
+ EXPECT_NO_THROW(process.getExitStatus(pid2));
+
+ process.clearStatus(pid2);
+ EXPECT_THROW(process.getExitStatus(pid2), InvalidOperation);
}
// This test verifies that the external application can be ran without