Use atexit to cleanup bus connections before exiting.

This commit is contained in:
Vibhav Pant
2023-09-03 13:10:18 +05:30
parent 4ec764950c
commit df5800fc70
2 changed files with 11 additions and 0 deletions
@@ -28,12 +28,18 @@ static std::unique_ptr<sdbus::IConnection> global_default_bus_connection =
nullptr;
static absl::once_flag bus_connection_init_;
static void disconnectBus() {
global_system_bus_connection = nullptr;
global_default_bus_connection = nullptr;
}
static void initBusConnections() {
global_system_bus_connection = sdbus::createSystemBusConnection();
global_system_bus_connection->enterEventLoopAsync();
global_default_bus_connection =
sdbus::createDefaultBusConnection("com.google.nearby");
global_default_bus_connection->enterEventLoopAsync();
atexit(disconnectBus);
}
sdbus::IConnection &getSystemBusConnection() {
@@ -33,9 +33,14 @@ namespace nearby {
static std::unique_ptr<linux::LogControl> global_log_control_;
static absl::once_flag log_control_init_;
static void cleanup_log_control() {
global_log_control_ = nullptr;
}
static void init_log_control(std::nullptr_t) {
global_log_control_ =
std::make_unique<linux::LogControl>(linux::getDefaultBusConnection());
atexit(cleanup_log_control);
}
namespace api {