From e5f7bf6a01844c6f0cee95fccf00205b070e822b Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Mon, 25 Jan 2021 17:57:49 +0100 Subject: [PATCH] libgdbus: Return null when dbus connection fails When libgdbus fails to get bus for one of global busses (system, session) it still returns vaild pointer. It's because global busses are cached in g_dh[2] which always exist. This commit changes the get_connection function to return null for all the checks like following to detect and fail in the case where getting bus was unsuccessfull (ie. dbus-daemon isn't running in early boot/special targets) dh = _dbus_handle_get_default_connection(); if (!dh) { _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); ... Change-Id: If85fe8e6cb7a5f95618df8f7f3fefa923e3e271a --- src/libgdbus/dbus-system.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index a78fe4d..f1278bf 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -212,10 +212,12 @@ static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type) if (!dh->conn) { dh->conn = _get_bus(bus_type); + if (!dh->conn) { + dbus_handle_unlock(dh); + return NULL; + } dh->priv = FALSE; dh->bus_type = bus_type; - if (!dh->conn) - dh = NULL; } dbus_handle_unlock(dh); -- 2.7.4