Move current daemon destruction logic to RealSystemState.
The UpdateAttempter requires to release the dbus_adaptor pointer
before detruction to avoid sending messages over a dead DBus connection.
This patch moves this logic out of the UpdateEngineDaemon class.
Bug: None
TEST=mm; Tested on Brillo.
Change-Id: I8939c5a2940f435e2e8f574910e0fa2674dc725f
diff --git a/daemon.cc b/daemon.cc
index dfad5c6..f7f2170 100644
--- a/daemon.cc
+++ b/daemon.cc
@@ -36,14 +36,6 @@
namespace chromeos_update_engine {
-UpdateEngineDaemon::~UpdateEngineDaemon() {
- UpdateAttempter* update_attempter = real_system_state_->update_attempter();
- // Prevent any DBus communication from UpdateAttempter when shutting down the
- // daemon.
- if (update_attempter)
- update_attempter->set_dbus_adaptor(nullptr);
-}
-
int UpdateEngineDaemon::OnInit() {
// Register the |subprocess_| singleton with this Daemon as the signal
// handler.
diff --git a/daemon.h b/daemon.h
index b6e9edc..31c4bf4 100644
--- a/daemon.h
+++ b/daemon.h
@@ -35,7 +35,6 @@
class UpdateEngineDaemon : public brillo::Daemon {
public:
UpdateEngineDaemon() = default;
- ~UpdateEngineDaemon();
protected:
int OnInit() override;
diff --git a/real_system_state.cc b/real_system_state.cc
index 349167b..906ec97 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -40,6 +40,13 @@
libcros_proxy_(bus) {
}
+RealSystemState::~RealSystemState() {
+ // Prevent any DBus communication from UpdateAttempter when shutting down the
+ // daemon.
+ if (update_attempter_)
+ update_attempter_->set_dbus_adaptor(nullptr);
+}
+
bool RealSystemState::Initialize() {
metrics_lib_.Init();
diff --git a/real_system_state.h b/real_system_state.h
index 3aaa9ec..a1fe8c6 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -49,6 +49,7 @@
// Constructs all system objects that do not require separate initialization;
// see Initialize() below for the remaining ones.
explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus);
+ ~RealSystemState() override;
// Initializes and sets systems objects that require an initialization
// separately from construction. Returns |true| on success.