From cf159a36c1f92937d9bc19a3572cde35bf7e1c7f Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Mon, 8 Aug 2016 14:24:03 +0200 Subject: [PATCH] fix objects termination clashes on shutdown --- server/Background.cc | 3 --- server/Background.h | 3 --- server/Client.cc | 25 ++++++++++++++++++------- server/Client.h | 15 +++++++++++---- server/snapperd.cc | 7 ++++++- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/server/Background.cc b/server/Background.cc index 21b580fa..32ad57c5 100644 --- a/server/Background.cc +++ b/server/Background.cc @@ -31,9 +31,6 @@ #include "Background.h" -Backgrounds backgrounds; - - Backgrounds::Backgrounds() { } diff --git a/server/Background.h b/server/Background.h index 70b46661..a8dbef18 100644 --- a/server/Background.h +++ b/server/Background.h @@ -75,7 +75,4 @@ private: }; -extern Backgrounds backgrounds; - - #endif diff --git a/server/Client.cc b/server/Client.cc index d56a967a..c658c167 100644 --- a/server/Client.cc +++ b/server/Client.cc @@ -37,11 +37,9 @@ boost::shared_mutex big_mutex; -Clients clients; - -Client::Client(const string& name) - : name(name), zombie(false) +Client::Client(const string& name, const Clients& clients) + : name(name), zombie(false), clients(clients) { } @@ -1027,7 +1025,7 @@ Client::create_post_snapshot(DBus::Connection& conn, DBus::Message& msg) bool background_comparison = true; it->getConfigInfo().getValue("BACKGROUND_COMPARISON", background_comparison); if (background_comparison) - backgrounds.add_task(it, snap1, snap2); + clients.backgrounds().add_task(it, snap1, snap2); DBus::MessageMethodReturn reply(msg); @@ -1431,7 +1429,7 @@ Client::debug(DBus::Connection& conn, DBus::Message& msg) const } hoho << "backgrounds:"; - for (Backgrounds::const_iterator it = backgrounds.begin(); it != backgrounds.end(); ++it) + for (Backgrounds::const_iterator it = clients.backgrounds().begin(); it != clients.backgrounds().end(); ++it) { std::ostringstream s; s << " name:'" << it->meta_snapper->configName() << "'"; @@ -1726,6 +1724,19 @@ Client::worker() } +Clients::Clients(Backgrounds& backgrounds) + : bgs(backgrounds) +{ +} + + +Backgrounds& +Clients::backgrounds() const +{ + return bgs; +} + + Clients::iterator Clients::find(const string& name) { @@ -1742,7 +1753,7 @@ Clients::add(const string& name) { assert(find(name) == entries.end()); - entries.emplace_back(name); + entries.emplace_back(name, *this); return --entries.end(); } diff --git a/server/Client.h b/server/Client.h index cad857b6..dbeb7a57 100644 --- a/server/Client.h +++ b/server/Client.h @@ -51,6 +51,9 @@ using namespace snapper; extern boost::shared_mutex big_mutex; +class Backgrounds; +class Clients; + struct NoComparison : Exception { @@ -112,7 +115,7 @@ public: void dispatch(DBus::Connection& conn, DBus::Message& msg); - Client(const string& name); + Client(const string& name, const Clients& clients); ~Client(); list::iterator find_comparison(Snapper* snapper, unsigned int number1, @@ -160,12 +163,15 @@ private: void worker(); + const Clients& clients; + }; class Clients { public: + Clients(Backgrounds& backgrounds); typedef list::iterator iterator; typedef list::const_iterator const_iterator; @@ -185,14 +191,15 @@ public: bool has_zombies() const; + Backgrounds& backgrounds() const; + private: list entries; -}; - + Backgrounds& bgs; -extern Clients clients; +}; #endif diff --git a/server/snapperd.cc b/server/snapperd.cc index 7e0c3403..8623015d 100644 --- a/server/snapperd.cc +++ b/server/snapperd.cc @@ -57,11 +57,16 @@ public: void periodic(); milliseconds periodic_timeout(); +private: + + Backgrounds backgrounds; + Clients clients; + }; MyMainLoop::MyMainLoop(DBusBusType type) - : MainLoop(type) + : MainLoop(type), backgrounds(), clients(backgrounds) { } -- 2.47.3