return conn;
}
+static GDBusConnection *get_dbus_private_connection(void)
+{
+ GError *err = NULL;
+ GDBusConnection *conn = NULL;
+ const char * address;
+
+ address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!address || err) {
+ _E("failed to get bus address\n");
+ g_error_free(err);
+ return NULL;
+ }
+
+ conn = g_dbus_connection_new_for_address_sync(address,
+ (GDBusConnectionFlags) (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
+ NULL, /* GDBusAuthObserver */
+ NULL,
+ &err);
+ if (!conn || err) {
+ _E("failed to get private bus\n");
+ g_error_free(err);
+ return NULL;
+ }
+
+ return conn;
+
+}
+
+static void free_dbus_connection(GDBusConnection *conn)
+{
+ assert(conn);
+
+ GError *err = NULL;
+ if (!g_dbus_connection_flush_sync(conn, NULL, &err)) {
+ _E("failed to flush %s\n", err->message);
+ g_error_free(err);
+ err = NULL;
+ }
+
+ if (!g_dbus_connection_close_sync(conn, NULL, &err)) {
+ _E("Error closing connection %s\n", err->message);
+ g_error_free(err);
+ err = NULL;
+ }
+
+ g_object_unref(conn);
+}
+
static void _cb_pending(GDBusConnection *conn,
GAsyncResult *res,
gpointer user_data)
if (!dest || !path || !iface || !method)
return NULL;
- conn = get_dbus_connection();
+ conn = get_dbus_private_connection();
if (!conn) {
_E("fail to get dbus connection"); //LCOV_EXCL_LINE
return NULL;
//LCOV_EXCL_STOP
}
+ free_dbus_connection(conn);
+
return ret;
}