[Spice-devel] [PATCH spice-gtk] desktop-integration: Create D-Bus proxy only when bus name exists

Marc-André Lureau marcandre.lureau at gmail.com
Wed Jan 28 02:50:26 PST 2015


On Wed, Jan 28, 2015 at 11:12 AM, Pavel Grunt <pgrunt at redhat.com> wrote:
> It avoids calling D-Bus methods when the bus name
> "org.gnome.SessionManager" does not exist.
>
> GSpice-WARNING **: Error calling 'org.gnome.SessionManager.Inhibit': GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
> ---
> The warning appears in other than Gnome desktop environment

Since it is required to prevent automount from racing with auto-usb
redirection, I would say that a warning is ok.

What desktop are you using? If you reach that error, it means there
was a org.gnome.SessionManager.

Maybe we should have a build option like --with-desktop=none ?

> ---
>  gtk/desktop-integration.c | 63 +++++++++++++++++++++++++++++++++--------------
>  1 file changed, 45 insertions(+), 18 deletions(-)
>
> diff --git a/gtk/desktop-integration.c b/gtk/desktop-integration.c
> index c366fd0..bf6a9e3 100644
> --- a/gtk/desktop-integration.c
> +++ b/gtk/desktop-integration.c
> @@ -44,6 +44,7 @@ struct _SpiceDesktopIntegrationPrivate {
>      GObject *gnome_session_proxy; /* dummy */
>  #endif
>      guint gnome_automount_inhibit_cookie;
> +    guint gdbus_watcher_id;
>  };
>
>  G_DEFINE_TYPE(SpiceDesktopIntegration, spice_desktop_integration, G_TYPE_OBJECT);
> @@ -60,33 +61,57 @@ static void handle_dbus_call_error(const char *call, GError **_error)
>      g_clear_error(_error);
>  }
>
> -static gboolean gnome_integration_init(SpiceDesktopIntegration *self)
> +#if defined(USE_GDBUS)
> +static void name_appeared_cb(GDBusConnection *connection,
> +                             const gchar *name,
> +                             const gchar *name_owner G_GNUC_UNUSED,
> +                             gpointer data)
>  {
> -    G_GNUC_UNUSED SpiceDesktopIntegrationPrivate *priv = self->priv;
> +    SpiceDesktopIntegration *self = SPICE_DESKTOP_INTEGRATION(data);
> +    SpiceDesktopIntegrationPrivate *priv = self->priv;
>      GError *error = NULL;
> -    gboolean success = TRUE;
> -
> -#if defined(USE_GDBUS)
> -    priv->gnome_session_proxy =
> -        g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
> -                                      G_DBUS_PROXY_FLAGS_NONE,
> -                                      NULL,
> -                                      "org.gnome.SessionManager",
> -                                      "/org/gnome/SessionManager",
> -                                      "org.gnome.SessionManager",
> -                                      NULL,
> -                                      &error);
> -#else
> -    success = FALSE;
> -#endif
>
> +    priv->gnome_session_proxy = g_dbus_proxy_new_sync(connection,
> +                                                      G_DBUS_PROXY_FLAGS_NONE,
> +                                                      NULL,
> +                                                      name,
> +                                                      "/org/gnome/SessionManager",
> +                                                      "org.gnome.SessionManager",
> +                                                      NULL,
> +                                                      &error);
>      if (error) {
>          g_warning("Could not create org.gnome.SessionManager dbus proxy: %s",
>                    error->message);
>          g_clear_error(&error);
> -        return FALSE;
>      }
> +}
> +
> +static void name_vanished_cb(GDBusConnection *connection G_GNUC_UNUSED,
> +                             const gchar *name G_GNUC_UNUSED,
> +                             gpointer data)
> +{
> +    SpiceDesktopIntegration *self = SPICE_DESKTOP_INTEGRATION(data);
> +    SpiceDesktopIntegrationPrivate *priv = self->priv;
> +
> +    g_clear_object(&priv->gnome_session_proxy);
> +}
> +#endif
>
> +static gboolean gnome_integration_init(SpiceDesktopIntegration *self)
> +{
> +    G_GNUC_UNUSED SpiceDesktopIntegrationPrivate *priv = self->priv;
> +    gboolean success = FALSE;
> +
> +#if defined(USE_GDBUS)
> +    priv->gdbus_watcher_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
> +                                              "org.gnome.SessionManager",
> +                                              G_BUS_NAME_WATCHER_FLAGS_NONE,
> +                                              name_appeared_cb,
> +                                              name_vanished_cb,
> +                                              self,
> +                                              NULL);
> +    success = TRUE;
> +#endif
>      return success;
>  }
>
> @@ -150,6 +175,8 @@ static void gnome_integration_dispose(SpiceDesktopIntegration *self)
>  {
>      SpiceDesktopIntegrationPrivate *priv = self->priv;
>
> +    if (priv->gdbus_watcher_id)
> +        g_bus_unwatch_name(priv->gdbus_watcher_id);

Dispose may be run multiple times, so you should clear
priv->gdbus_watcher_id too.


>      g_clear_object(&priv->gnome_session_proxy);
>  }
>
> --
> 1.9.3
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel

thanks

-- 
Marc-André Lureau


More information about the Spice-devel mailing list