[gjs/332-fix-dbus-connection] gdbus-wrapper: Guard against emitting signals when object isn't exported




commit 0b61a9ae8d9bbe727f695a25b4163406c41252d8
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Aug 9 12:20:02 2020 -0700

    gdbus-wrapper: Guard against emitting signals when object isn't exported
    
    g_dbus_interface_skeleton_get_connection() can return null if the
    object isn't exported on the bus. In those cases, refrain from trying to
    emit signals.
    
    Closes: #332

 libgjs-private/gjs-gdbus-wrapper.c | 39 +++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
---
diff --git a/libgjs-private/gjs-gdbus-wrapper.c b/libgjs-private/gjs-gdbus-wrapper.c
index d534d9b4..c7438400 100644
--- a/libgjs-private/gjs-gdbus-wrapper.c
+++ b/libgjs-private/gjs-gdbus-wrapper.c
@@ -250,16 +250,18 @@ gjs_dbus_implementation_flush (GDBusInterfaceSkeleton *skeleton) {
             g_variant_builder_add(&invalidated_props, "s", prop_name);
     }
 
-    g_dbus_connection_emit_signal(g_dbus_interface_skeleton_get_connection(skeleton),
-                                  NULL, /* bus name */
-                                  g_dbus_interface_skeleton_get_object_path(skeleton),
-                                  "org.freedesktop.DBus.Properties",
-                                  "PropertiesChanged",
-                                  g_variant_new("(s@a{sv}@as)",
-                                                self->priv->ifaceinfo->name,
-                                                g_variant_builder_end(&changed_props),
-                                                g_variant_builder_end(&invalidated_props)),
-                                   NULL /* error */);
+    GDBusConnection* connection =
+        g_dbus_interface_skeleton_get_connection(skeleton);
+    if (connection) {
+        g_dbus_connection_emit_signal(
+            connection, /* bus_name = */ NULL,
+            g_dbus_interface_skeleton_get_object_path(skeleton),
+            "org.freedesktop.DBus.Properties", "PropertiesChanged",
+            g_variant_new("(s@a{sv}@as)", self->priv->ifaceinfo->name,
+                          g_variant_builder_end(&changed_props),
+                          g_variant_builder_end(&invalidated_props)),
+            /* error = */ NULL);
+    }
 
     g_hash_table_remove_all(self->priv->outstanding_properties);
     g_clear_handle_id(&self->priv->idle_id, g_source_remove);
@@ -368,11 +370,14 @@ gjs_dbus_implementation_emit_signal (GjsDBusImplementation *self,
 {
     GDBusInterfaceSkeleton *skeleton = G_DBUS_INTERFACE_SKELETON (self);
 
-    g_dbus_connection_emit_signal(g_dbus_interface_skeleton_get_connection(skeleton),
-                                  NULL,
-                                  g_dbus_interface_skeleton_get_object_path(skeleton),
-                                  self->priv->ifaceinfo->name,
-                                  signal_name,
-                                  parameters,
-                                  NULL);
+    GDBusConnection* connection =
+        g_dbus_interface_skeleton_get_connection(skeleton);
+    if (!connection)
+        return;
+
+    g_dbus_connection_emit_signal(
+        connection, /* bus_name = */ NULL,
+        g_dbus_interface_skeleton_get_object_path(skeleton),
+        self->priv->ifaceinfo->name, signal_name, parameters,
+        /* error = */ NULL);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]