void
RunScriptImpl::runScript(const ProcessArgs& args, const ProcessEnvVars& vars) {
ProcessSpawn process(io_service_, name_, args, vars);
- process.spawn();
+ process.spawn(true);
}
void
/// @brief Get name of the target script.
///
/// @return The name of the target script.
- std::string getName() {
+ std::string getName() const {
return (name_);
}
/// @brief Get the synchronous call mode for the target script.
///
/// @return The synchronous call mode for the target script.
- bool getSync() {
+ bool getSync() const {
return (sync_);
}
namespace asiolink {
/// @brief Implementation class of IOSignalSet.
-class IOSignalSetImpl :
- public boost::enable_shared_from_this<IOSignalSetImpl>,
- public boost::noncopyable {
+class IOSignalSetImpl : public boost::enable_shared_from_this<IOSignalSetImpl>,
+ public boost::noncopyable {
public:
/// @brief Constructor.
///
IOSignalSetImpl(IOServicePtr io_service, IOSignalHandler handler);
/// @brief Destructor.
- ~IOSignalSetImpl(){}
+ ~IOSignalSetImpl() = default;
/// @brief Install the callback on the IO service queue.
void install();
- /// @brief Add a signal in the ASIO signal set.
+ /// @brief Add a signal to the ASIO signal set.
///
/// @param signum the signal number.
void add(int signum);
+ /// @brief Remove a signal from the ASIO signal set.
+ ///
+ /// @param signum the signal number.
+ void remove(int signum);
+
private:
/// @brief the ASIO signal set.
boost::asio::signal_set signal_set_;
try {
signal_set_.add(signum);
} catch (const boost::system::system_error& ex) {
- isc_throw(isc::Unexpected, "Failed to add signal " << signum
- << ": " << ex.what());
+ isc_throw(isc::Unexpected,
+ "Failed to add signal " << signum << ": " << ex.what());
+ }
+}
+
+void
+IOSignalSetImpl::remove(int signum) {
+ try {
+ signal_set_.remove(signum);
+ } catch (const boost::system::system_error& ex) {
+ isc_throw(isc::Unexpected,
+ "Failed to add signal " << signum << ": " << ex.what());
}
}
impl_->install();
}
-IOSignalSet::~IOSignalSet() {
- impl_.reset();
-}
-
void
IOSignalSet::add(int signum) {
impl_->add(signum);
}
+void
+IOSignalSet::remove(int signum) {
+ impl_->remove(signum);
+}
+
} // namespace asiolink
} // namespace isc
IOSignalSet(asiolink::IOServicePtr io_service, IOSignalHandler handler);
/// @brief Destructor.
- ~IOSignalSet();
+ ~IOSignalSet() = default;
/// @brief Add a signal to the list of signals to handle.
///
/// @throw Unexpected on error.
void add(int signum);
+ /// @brief Remove a signal from the list of signals to handle.
+ ///
+ /// @param signum Signal number.
+ /// @throw Unexpected on error.
+ void remove(int signum);
+
private:
/// @brief Pointer to the implementation.
boost::shared_ptr<IOSignalSetImpl> impl_;
/// or when the executable does not exist. If the process ends successfully
/// the EXIT_SUCCESS is returned.
///
+ /// @param dismiss The flag which indicated if the process status can be
+ /// disregarded.
/// @return PID of the spawned process.
/// @throw ProcessSpawnError if forking a current process failed.
- pid_t spawn();
+ pid_t spawn(bool dismiss);
/// @brief Checks if the process is still running.
///
/// was a different signal.
bool waitForProcess(int signum);
- /// @brief ASIO signal set.
- IOSignalSetPtr io_signal_set_;
-
/// @brief A map holding the status codes of executed processes.
ProcessStates process_state_;
/// @brief Mutex to protect internal state.
boost::shared_ptr<std::mutex> mutex_;
+
+ /// @brief ASIO signal set.
+ IOSignalSetPtr io_signal_set_;
};
ProcessSpawnImpl::ProcessSpawnImpl(IOServicePtr io_service,
const ProcessArgs& args,
const ProcessEnvVars& vars)
: executable_(executable), args_(new char*[args.size() + 2]),
- vars_(new char*[vars.size() + 1]), mutex_(new std::mutex) {
- io_signal_set_.reset(new IOSignalSet(io_service,
- std::bind(&ProcessSpawnImpl::waitForProcess,
- this, ph::_1)));
+ vars_(new char*[vars.size() + 1]), mutex_(new std::mutex),
+ io_signal_set_(new IOSignalSet(io_service,
+ std::bind(&ProcessSpawnImpl::waitForProcess,
+ this, ph::_1))) {
io_signal_set_->add(SIGCHLD);
// Conversion of the arguments to the C-style array we start by setting
}
ProcessSpawnImpl::~ProcessSpawnImpl() {
+ io_signal_set_->remove(SIGCHLD);
}
std::string
}
pid_t
-ProcessSpawnImpl::spawn() {
+ProcessSpawnImpl::spawn(bool dismiss) {
// Protect us against SIGCHLD signals
sigset_t sset;
sigset_t osset;
}
// We're in the parent process.
- try {
- lock_guard<std::mutex> lk(*mutex_);
- process_state_.insert(std::pair<pid_t, ProcessState>(pid, ProcessState()));
- } catch(...) {
- pthread_sigmask(SIG_SETMASK, &osset, 0);
- throw;
+ if (!dismiss) {
+ try {
+ lock_guard<std::mutex> lk(*mutex_);
+ process_state_.insert(std::pair<pid_t, ProcessState>(pid, ProcessState()));
+ } catch(...) {
+ pthread_sigmask(SIG_SETMASK, &osset, 0);
+ throw;
+ }
}
pthread_sigmask(SIG_SETMASK, &osset, 0);
return (pid);
}
pid_t
-ProcessSpawn::spawn() {
- return (impl_->spawn());
+ProcessSpawn::spawn(bool dismiss) {
+ return (impl_->spawn(dismiss));
}
bool
/// or when the executable does not exist. If the process ends successfully
/// the EXIT_SUCCESS is returned.
///
+ /// @param dismiss The flag which indicated if the process status can be
+ /// disregarded.
/// @throw ProcessSpawnError if forking a current process failed.
- pid_t spawn();
+ pid_t spawn(bool dismiss = false);
/// @brief Checks if the process is still running.
///
- read-write mutex (header only).
- - signal set: signal handling (please use @c isc::process::IOSignalSet
+ - signal set: signal handling (please use @c isc::asiolink::IOSignalSet
instead).
- staged values.