From 28921ad424de293541fe8e5787a404201d88535e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislav=20Angelovi=C4=8D?= Date: Sat, 30 Dec 2023 17:37:00 +0100 Subject: [PATCH] fix: request name signal handling issue (#392) In case a signal arrives during the `RequestName` or `ReleaseName` D-Bus call (which is a synchronous call), the signal may not be processed immediately, which is a bug. This is solved now by waking up the event loop. --- src/Connection.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Connection.cpp b/src/Connection.cpp index 2a51bd5..95813ff 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -108,12 +108,20 @@ void Connection::requestName(const std::string& name) auto r = iface_->sd_bus_request_name(bus_.get(), name.c_str(), 0); SDBUS_THROW_ERROR_IF(r < 0, "Failed to request bus name", -r); + + // In some cases we need to explicitly notify the event loop + // to process messages that may have arrived while executing the call. + notifyEventLoop(eventFd_.fd); } void Connection::releaseName(const std::string& name) { auto r = iface_->sd_bus_release_name(bus_.get(), name.c_str()); SDBUS_THROW_ERROR_IF(r < 0, "Failed to release bus name", -r); + + // In some cases we need to explicitly notify the event loop + // to process messages that may have arrived while executing the call. + notifyEventLoop(eventFd_.fd); } std::string Connection::getUniqueName() const