diff options
-rw-r--r-- | include/dbus_singleton.hpp | 6 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | src/dbus_singleton.cpp | 13 | ||||
-rw-r--r-- | src/webserver_main.cpp | 7 |
4 files changed, 23 insertions, 4 deletions
diff --git a/include/dbus_singleton.hpp b/include/dbus_singleton.hpp index 63c88b7544..283021641b 100644 --- a/include/dbus_singleton.hpp +++ b/include/dbus_singleton.hpp @@ -1,11 +1,15 @@ #pragma once +#include <boost/asio/io_context.hpp> #include <sdbusplus/asio/connection.hpp> namespace crow { namespace connections { -static std::shared_ptr<sdbusplus::asio::connection> systemBus; + +// Initialze before using! +// Please see webserver_main for the example how this variable is initialzed, +extern sdbusplus::asio::connection* systemBus; } // namespace connections } // namespace crow diff --git a/meson.build b/meson.build index 1ed9bfd79f..79cc5f9018 100644 --- a/meson.build +++ b/meson.build @@ -368,6 +368,7 @@ srcfiles_bmcweb = [ 'src/boost_asio.cpp', 'src/boost_beast.cpp', 'src/boost_url.cpp', + 'src/dbus_singleton.cpp', ] # Generate the bmcweb executable diff --git a/src/dbus_singleton.cpp b/src/dbus_singleton.cpp new file mode 100644 index 0000000000..f78164fbe2 --- /dev/null +++ b/src/dbus_singleton.cpp @@ -0,0 +1,13 @@ +#include "dbus_singleton.hpp" + +#include <boost/asio/io_context.hpp> + +namespace crow +{ +namespace connections +{ + +sdbusplus::asio::connection* systemBus = nullptr; + +} // namespace connections +} // namespace crow diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp index ff0bbd7420..c306dea958 100644 --- a/src/webserver_main.cpp +++ b/src/webserver_main.cpp @@ -65,8 +65,8 @@ static int run() auto io = std::make_shared<boost::asio::io_context>(); App app(io); - crow::connections::systemBus = - std::make_shared<sdbusplus::asio::connection>(*io); + sdbusplus::asio::connection systemBus(*io); + crow::connections::systemBus = &systemBus; // Static assets need to be initialized before Authorization, because auth // needs to build the whitelist from the static routes @@ -147,7 +147,8 @@ static int run() app.run(); io->run(); - crow::connections::systemBus.reset(); + crow::connections::systemBus = nullptr; + return 0; } |