From e492cd1af8870cc7ef5ffdeea0dca69231f93c79 Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Fri, 12 May 2017 14:00:36 +0100 Subject: [PATCH] cmds: session_manager: Handle the Container Client class using pointers We can now start the Session Manager in Stand Alone Mode. This means that the Container Manager is not required, since the assumption is that the user will provide their own container. The issue is that the container related calls are spread throughout the Session Manager's code base. So if we attempt to take an instance of the Container Client class in one if-ed out area, by the time we reach the next, it will be out of scope. One solution is to take the instance of the Container Client class globally, then only make use of it if it's required. This works great if the Container Manager is running in the background. However, since a connection is made to the Container Manager during the constructor, if the Container Manager is not running, the side-effect is the following error: Failed to connect to socket /run/anbox-container.socket: Connection refused To solve this problem we will use a global (actually private to the Session Manager) pointer which will always be in scope. It will only be initialised and used when required though. Signed-off-by: Lee Jones --- src/anbox/cmds/session_manager.cpp | 8 ++++---- src/anbox/cmds/session_manager.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/anbox/cmds/session_manager.cpp b/src/anbox/cmds/session_manager.cpp index d0ce924..5a46566 100644 --- a/src/anbox/cmds/session_manager.cpp +++ b/src/anbox/cmds/session_manager.cpp @@ -146,9 +146,9 @@ anbox::cmds::SessionManager::SessionManager(const BusFactory &bus_factory) auto rt = Runtime::create(); auto dispatcher = anbox::common::create_dispatcher_for_runtime(rt); - container::Client container(rt); if (!standalone_) { - container.register_terminate_handler([&]() { + container_ = std::make_shared(rt); + container_->register_terminate_handler([&]() { WARNING("Lost connection to container manager, terminating."); trap->stop(); }); @@ -237,7 +237,7 @@ anbox::cmds::SessionManager::SessionManager(const BusFactory &bus_factory) {"/dev/fuse", "/dev/fuse"}, }; - dispatcher->dispatch([&]() { container.start(container_configuration); }); + dispatcher->dispatch([&]() { container_->start(container_configuration); }); } auto bus = bus_factory_(); @@ -251,7 +251,7 @@ anbox::cmds::SessionManager::SessionManager(const BusFactory &bus_factory) if (!standalone_) { // Stop the container which should close all open connections we have on // our side and should terminate all services. - container.stop(); + container_->stop(); } rt->stop(); diff --git a/src/anbox/cmds/session_manager.h b/src/anbox/cmds/session_manager.h index 498f5a5..25185ac 100644 --- a/src/anbox/cmds/session_manager.h +++ b/src/anbox/cmds/session_manager.h @@ -30,6 +30,9 @@ #include "anbox/graphics/rect.h" namespace anbox { +namespace container { +class Client; +} // namespace container namespace cmds { class SessionManager : public cli::CommandWithFlagsAndAction { public: @@ -40,6 +43,7 @@ class SessionManager : public cli::CommandWithFlagsAndAction { SessionManager(const BusFactory& bus_factory = session_bus_factory()); private: + std::shared_ptr container_; BusFactory bus_factory_; std::string desktop_file_hint_; graphics::GLRendererServer::Config::Driver gles_driver_;