diff options
author | Razvan Becheriu <razvan@isc.org> | 2021-02-15 12:57:14 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2021-02-18 18:14:27 +0100 |
commit | 3ecd0e96fe8207a45ded6dfdc57d36d336e004e2 (patch) | |
tree | 6ce9773420f151827fd65cc90f4c3a6c04ab4d86 /src/lib | |
parent | [#899] addressed comments (diff) | |
download | kea-3ecd0e96fe8207a45ded6dfdc57d36d336e004e2.tar.xz kea-3ecd0e96fe8207a45ded6dfdc57d36d336e004e2.zip |
[#899] use only one instance of SignalSet to handle SIGCHLD signal
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/util/process_spawn.cc | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/lib/util/process_spawn.cc b/src/lib/util/process_spawn.cc index a87bc61a2a..ad24597f14 100644 --- a/src/lib/util/process_spawn.cc +++ b/src/lib/util/process_spawn.cc @@ -116,6 +116,13 @@ public: private: + /// @brief Access the single instance of the SignalSet which registers the + /// @ref waitForProcess function as the SIGCHLD signal handler. + /// + /// @return The single instance of the @ref SignalSet which handles the + /// SIGCHLD signal. + SignalSetPtr signalSet(); + /// @brief Copies the argument specified as a C++ string to the new /// C string. /// @@ -165,13 +172,8 @@ private: ProcessSpawnImpl::ProcessSpawnImpl(const std::string& executable, const ProcessArgs& args, const ProcessEnvVars& vars) - : signals_(new SignalSet(SIGCHLD)), process_state_(), - executable_(executable), args_(new char*[args.size() + 2]), - vars_(new char*[vars.size() + 1]) { - // Set the handler which is invoked immediately when the signal - // is received. - signals_->setOnReceiptHandler(std::bind(&ProcessSpawnImpl::waitForProcess, - this, ph::_1)); + : signals_(signalSet()), process_state_(), executable_(executable), + args_(new char*[args.size() + 2]), vars_(new char*[vars.size() + 1]) { // Conversion of the arguments to the C-style array we start by setting // all pointers within an array to NULL to indicate that they haven't // been allocated yet. @@ -192,6 +194,22 @@ ProcessSpawnImpl::ProcessSpawnImpl(const std::string& executable, ProcessSpawnImpl::~ProcessSpawnImpl() { } +SignalSetPtr +ProcessSpawnImpl::signalSet() { + static SignalSetPtr signals(new SignalSet(SIGCHLD)); + auto registerHandle = [&]() -> bool { + // Set the handler which is invoked immediately when the signal + // is received. + signals->setOnReceiptHandler(std::bind(&ProcessSpawnImpl::waitForProcess, + this, ph::_1)); + return (true); + }; + static bool init = registerHandle(); + (void)init; + + return (signals); +} + std::string ProcessSpawnImpl::getCommandLine() const { std::ostringstream s; |