From b8c0e84f0155f4e83620486501dd7a09c447bc4a Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Wed, 14 Oct 2020 16:22:42 -0700 Subject: [PATCH] Fix codecheck Signed-off-by: Louise Poubel --- src/Manager.cc | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Manager.cc b/src/Manager.cc index e9a4d51a..d0ceea09 100644 --- a/src/Manager.cc +++ b/src/Manager.cc @@ -178,7 +178,7 @@ class ignition::launch::ManagerPrivate /// \brief Semaphore to prevent restartThread from being a spinlock private: sem_t *stoppedChildSem; - + /// \brief Name of the semaphore created by stoppedChildSem. private: std::string stoppedChildSemName; @@ -299,24 +299,30 @@ ManagerPrivate::ManagerPrivate() std::bind(&ManagerPrivate::OnSigIntTerm, this, std::placeholders::_1)); { - // The semaphore we initialize in the next section needs a unique name, so we need - // to seed a random number generator with a quality random number. Especially time(0) - // itself is not a good seed as there may be multiple processes launched at the same time. + // The semaphore we initialize in the next section needs a unique name, so + // we need to seed a random number generator with a quality random number. + // Especially time(0) itself is not a good seed as there may be multiple + // processes launched at the same time. const auto time_seed = static_cast(std::time(nullptr)); - const auto pid_seed = std::hash()(std::this_thread::get_id()); + const auto pid_seed = std::hash()( + std::this_thread::get_id()); std::seed_seq seed_value{time_seed, pid_seed}; std::vector seeds(1); seed_value.generate(seeds.begin(), seeds.end()); math::Rand::Seed(seeds[0]); } - const auto semRandomId = math::Rand::IntUniform(0, std::numeric_limits::max()); + const auto semRandomId = math::Rand::IntUniform(0, + std::numeric_limits::max()); // Initialize semaphore - this->stoppedChildSemName = std::string("ign-launch-") + std::to_string(semRandomId); - this->stoppedChildSem = sem_open(this->stoppedChildSemName.c_str(), O_CREAT, 0644, 1); - if (this->stoppedChildSem == SEM_FAILED) { - ignerr << "Error initializing semaphore " << this->stoppedChildSemName << ": " << - strerror(errno) << std::endl; + this->stoppedChildSemName = std::string("ign-launch-") + + std::to_string(semRandomId); + this->stoppedChildSem = sem_open(this->stoppedChildSemName.c_str(), O_CREAT, + 0644, 1); + if (this->stoppedChildSem == SEM_FAILED) + { + ignerr << "Error initializing semaphore " << this->stoppedChildSemName + << ": " << strerror(errno) << std::endl; } // Register a signal handler to capture child process death events. @@ -324,7 +330,8 @@ ManagerPrivate::ManagerPrivate() ignerr << "signal(2) failed while setting up for SIGCHLD" << std::endl; // Register backward signal handler for other signals - std::vector signals = { + std::vector signals = + { SIGABRT, // Abort signal from abort(3) SIGBUS, // Bus error (bad memory access) SIGFPE, // Floating point exception @@ -348,14 +355,14 @@ ManagerPrivate::~ManagerPrivate() { if (sem_close(this->stoppedChildSem) == -1) { - ignerr << "Failed to close semaphore " << this->stoppedChildSemName << ": " << - strerror(errno) << std::endl; + ignerr << "Failed to close semaphore " << this->stoppedChildSemName + << ": " << strerror(errno) << std::endl; } if (sem_unlink(this->stoppedChildSemName.c_str()) == -1) { - ignerr << "Failed to unlink semaphore " << this->stoppedChildSemName << ": " << - strerror(errno) << std::endl; + ignerr << "Failed to unlink semaphore " << this->stoppedChildSemName + << ": " << strerror(errno) << std::endl; } } }