Enable module in start funcion (#2538)

Before it was enabled by default. That means if the constructor fails,
the destructor will complain that the module was not stopped before
deconstructing.

We can't just call stop if module creation fails because the module is
only partially initialized.
This commit is contained in:
Patrick Ziegler 2021-10-15 10:33:10 +02:00 committed by GitHub
parent 76ae61f892
commit abd96eb089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 1 deletions

View File

@ -158,6 +158,7 @@ namespace modules {
bool visible() const override;
void start() override;
void join() final override;
void stop() override;
void halt(string error_message) override;
@ -218,7 +219,7 @@ namespace modules {
bool m_handle_events{true};
private:
atomic<bool> m_enabled{true};
atomic<bool> m_enabled{false};
atomic<bool> m_visible{true};
atomic<bool> m_changed{true};
string m_cache;

View File

@ -65,6 +65,11 @@ namespace modules {
return static_cast<bool>(m_enabled);
}
template <class Impl>
void module<Impl>::start() {
m_enabled = true;
}
template <class Impl>
void module<Impl>::join() {
for (auto&& thread_ : m_threads) {

View File

@ -11,6 +11,7 @@ namespace modules {
using module<Impl>::module;
void start() override {
this->module<Impl>::start();
this->m_mainthread = thread(&event_module::runner, this);
}

View File

@ -12,6 +12,7 @@ namespace modules {
using module<Impl>::module;
void start() override {
this->module<Impl>::start();
this->m_mainthread = thread(&inotify_module::runner, this);
}

View File

@ -11,6 +11,7 @@ namespace modules {
using module<Impl>::module;
void start() override {
this->module<Impl>::start();
CAST_MOD(Impl)->update();
CAST_MOD(Impl)->broadcast();
}

View File

@ -13,6 +13,7 @@ namespace modules {
using module<Impl>::module;
void start() override {
this->module<Impl>::start();
this->m_mainthread = thread(&timer_module::runner, this);
}

View File

@ -68,6 +68,7 @@ namespace modules {
* Start module and run first defined hook if configured to
*/
void ipc_module::start() {
this->module::start();
m_mainthread = thread([&] {
m_log.trace("%s: Thread id = %i", this->name(), concurrency_util::thread_id(this_thread::get_id()));
update();

View File

@ -33,6 +33,7 @@ namespace modules {
* Start the module worker
*/
void script_module::start() {
this->module::start();
m_mainthread = thread([&] {
try {
while (running()) {