From cffedf6d54801ff9804ead948d8808771db5e9ae Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Tue, 3 Apr 2012 16:17:37 -0400 Subject: [PATCH] * #9688: gnome: screensaver_uninhibit must verify that the cookie has been set --- gnome/src/dbus/dbus.c | 87 ++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index e2b184b3f3..c49bd52115 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -613,7 +613,7 @@ screensaver_dbus_proxy_new_cb (GObject * source UNUSED, GAsyncResult *result, gp gboolean dbus_connect_session_manager(DBusGConnection *connection) { - if(connection == NULL) { + if (connection == NULL) { ERROR("DBUS: Error connection is NULL"); return FALSE; } @@ -628,8 +628,10 @@ gboolean dbus_connect_session_manager(DBusGConnection *connection) } */ - g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, GS_SERVICE, GS_PATH, GS_INTERFACE, NULL, screensaver_dbus_proxy_new_cb, NULL); + g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, GS_SERVICE, GS_PATH, GS_INTERFACE, NULL, + screensaver_dbus_proxy_new_cb, NULL); DEBUG("DBUS: Connected to gnome session manager"); @@ -1891,86 +1893,87 @@ dbus_send_text_message(const gchar *callID, const gchar *message) static guint cookie; #define GNOME_SESSION_NO_IDLE_FLAG 8 -static void screensaver_inhibit_cb (GObject * source_object, GAsyncResult * res, gpointer user_data UNUSED) +static void screensaver_inhibit_cb(GObject * source_object, GAsyncResult * res, + gpointer user_data UNUSED) { - DEBUG("Screensaver: Inhibit callback"); - - GDBusProxy *proxy = G_DBUS_PROXY (source_object); - // ScreenSaver *screensaver = (ScreenSaver *) user_data; - GVariant *value; + DEBUG(__PRETTY_FUNCTION__); + GDBusProxy *proxy = G_DBUS_PROXY(source_object); GError *error = NULL; - - value = g_dbus_proxy_call_finish (proxy, res, &error); + GVariant *value = g_dbus_proxy_call_finish(proxy, res, &error); if (!value) { - ERROR ("Screensaver: Error: inhibiting the screensaver: %s", error->message); - g_error_free (error); + ERROR("Screensaver: Error: inhibiting the screensaver: %s", error->message); + g_error_free(error); return; } /* save the cookie */ - if (g_variant_is_of_type (value, G_VARIANT_TYPE ("(u)"))) - g_variant_get (value, "(u)", &cookie); + if (g_variant_is_of_type(value, G_VARIANT_TYPE("(u)"))) + g_variant_get(value, "(u)", &cookie); else cookie = 0; - g_variant_unref (value); + g_variant_unref(value); } -static void screensaver_uninhibit_cb (GObject * source_object, GAsyncResult * res, gpointer user_data UNUSED) +static void screensaver_uninhibit_cb(GObject * source_object, + GAsyncResult * res, + gpointer user_data UNUSED) { - DEBUG("Screensaver: Uninhibit callback"); - - GDBusProxy *proxy = G_DBUS_PROXY (source_object); - // ScreenSaver *screensaver = (ScreenSaver *) user_data; - GVariant *value; + DEBUG(__PRETTY_FUNCTION__); + GDBusProxy *proxy = G_DBUS_PROXY(source_object); GError *error = NULL; - value = g_dbus_proxy_call_finish (proxy, res, &error); + GVariant *value = g_dbus_proxy_call_finish(proxy, res, &error); if (!value) { - ERROR ("Screensaver: Error uninhibiting the screensaver: %s", error->message); - g_error_free (error); + ERROR ("Screensaver: Error uninhibiting the screensaver: %s", + error->message); + g_error_free(error); return; } /* clear the cookie */ cookie = 0; - g_variant_unref (value); - + g_variant_unref(value); } void dbus_screensaver_inhibit(void) { - guint xid = 0; - - DEBUG("Screensaver: inhibit"); - const gchar *appname = g_get_application_name(); - if(appname == NULL) { - ERROR("Screensaver: Could not retreive application name"); + if (appname == NULL) { + ERROR("Screensaver: Could not retrieve application name"); return; } - GVariant *parameters = g_variant_new ("(susu)", appname, xid, "Phone call ongoing", GNOME_SESSION_NO_IDLE_FLAG); - if(parameters == NULL) { + guint xid = 0; + GVariant *parameters = g_variant_new("(susu)", appname, xid, + "Phone call ongoing", + GNOME_SESSION_NO_IDLE_FLAG); + if (parameters == NULL) { ERROR("Screensaver: Could not create session manager inhibit parameters"); return; } - g_dbus_proxy_call (session_manager_proxy, "Inhibit", parameters, - G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, screensaver_inhibit_cb, NULL); + g_dbus_proxy_call(session_manager_proxy, "Inhibit", parameters, + G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, + screensaver_inhibit_cb, NULL); } void dbus_screensaver_uninhibit(void) { + if (cookie == 0) + return; DEBUG("Screensaver: uninhibit"); GVariant *parameters = g_variant_new("(u)", cookie); - if(parameters == NULL) { - ERROR("Screensaver: Could not create session manager uninhibit parameters"); + if (parameters == NULL) { + ERROR("Screensaver: Could not create session manager uninhibit " + "parameters"); return; - }; + } - g_dbus_proxy_call (session_manager_proxy, "Uninhibit", g_variant_new ("(u)", cookie), - G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, screensaver_uninhibit_cb, NULL); + g_dbus_proxy_call(session_manager_proxy, "Uninhibit", + g_variant_new("(u)", cookie), + G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, + screensaver_uninhibit_cb, NULL); } -- GitLab