From a1ea3fece0ded0f1a17198d47855f26b1841ee2e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 11 Apr 2014 13:53:20 -0500 Subject: try to log out with com.canonical.Unity.Session's RequestLogout. If that fails, fall back to org.gnome.SessionManager's Logout. --- src/backend-dbus/actions.c | 121 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/backend-dbus/actions.c b/src/backend-dbus/actions.c index cac7c40..503f1b8 100644 --- a/src/backend-dbus/actions.c +++ b/src/backend-dbus/actions.c @@ -471,18 +471,103 @@ my_hibernate (IndicatorSessionActions * self) **** End Session Dialog ***/ +static gboolean +is_owned_proxy (gpointer proxy) +{ + gboolean owned = FALSE; + + if ((proxy != NULL) && G_IS_DBUS_PROXY (proxy)) + { + char * name_owner = g_dbus_proxy_get_name_owner (proxy); + + if (name_owner != NULL) + { + owned = TRUE; + g_free (name_owner); + } + } + + return owned; +} + static void -logout_now (IndicatorSessionActionsDbus * self) +on_gnome_logout_response (GObject * o, + GAsyncResult * res, + gpointer unused G_GNUC_UNUSED) +{ + GError * err = NULL; + gnome_session_manager_call_logout_finish (GNOME_SESSION_MANAGER(o), res, &err); + log_and_clear_error (&err, G_STRLOC, G_STRFUNC); +} + +static gboolean +logout_now_gnome_session_manager (IndicatorSessionActionsDbus * self) { + gboolean logout_called = FALSE; priv_t * p = self->priv; - g_return_if_fail (p->session_manager != NULL); + if (is_owned_proxy (p->session_manager)) + { + g_debug ("%s: calling gnome_session_manager_call_logout()", G_STRFUNC); + gnome_session_manager_call_logout (p->session_manager, + 1, /* don't prompt */ + p->cancellable, + on_gnome_logout_response, + self); + logout_called = TRUE; + } - gnome_session_manager_call_logout (p->session_manager, - 1, /* don't prompt */ - p->cancellable, - NULL, - NULL); + return logout_called; +} + +static void +on_unity_logout_response (GObject * o, + GAsyncResult * res, + gpointer gself) +{ + GError * error; + + error = NULL; + unity_session_call_request_logout_finish (UNITY_SESSION(o), res, &error); + + if (error != NULL) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + g_warning ("%s %s: %s", G_STRLOC, G_STRFUNC, error->message); + logout_now_gnome_session_manager(gself); + } + + g_clear_error (&error); + } +} + +static gboolean +logout_now_unity (IndicatorSessionActionsDbus * self) +{ + priv_t * p = self->priv; + gboolean called = FALSE; + + if (is_owned_proxy (p->unity_session)) + { + called = TRUE; + g_debug ("calling unity_session_call_request_logout()"); + unity_session_call_request_logout (p->unity_session, + p->cancellable, + on_unity_logout_response, + self); + } + + return called; +} + +static void +logout_now (IndicatorSessionActionsDbus * self) +{ + if (!logout_now_unity(self) && !logout_now_gnome_session_manager(self)) + { + g_critical("%s can't logout: no Unity nor GNOME session proxy", G_STRFUNC); + } } static void @@ -776,32 +861,12 @@ my_about (IndicatorSessionActions * self G_GNUC_UNUSED) **** ***/ -static gboolean -have_unity_session (IndicatorSessionActions * self) -{ - priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv; - gchar * name_owner; - - if (G_IS_DBUS_PROXY (p->unity_session)) - { - name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (p->unity_session)); - - if (name_owner) - { - g_free (name_owner); - return TRUE; - } - } - - return FALSE; -} - static void lock_current_session (IndicatorSessionActions * self, gboolean immediate) { priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv; - if (have_unity_session (self)) + if (is_owned_proxy (p->unity_session)) { if (immediate) { -- cgit v1.2.3 From 96bc6e532df0611fb12fdcb4ccb346a248461d58 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 18 Jun 2014 15:33:39 -0500 Subject: If we try to prompt for confirmation with zenity but zenity fails to run, treat that as confirmation. Otherwise how will a user ever log out? --- src/backend-dbus/actions.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/backend-dbus/actions.c b/src/backend-dbus/actions.c index 503f1b8..5447440 100644 --- a/src/backend-dbus/actions.c +++ b/src/backend-dbus/actions.c @@ -669,6 +669,7 @@ zenity_question (IndicatorSessionActionsDbus * self, { char * command_line; int exit_status; + GError * error; gboolean confirmed; command_line = g_strdup_printf ("%s" @@ -686,11 +687,16 @@ zenity_question (IndicatorSessionActionsDbus * self, ok_label, cancel_label); + /* Treat errors as user confirmation. + Otherwise how will the user ever log out? */ exit_status = -1; - if (!g_spawn_command_line_sync (command_line, NULL, NULL, &exit_status, NULL)) + error = NULL; + if (!g_spawn_command_line_sync (command_line, NULL, NULL, &exit_status, &error)) + { + confirmed = TRUE; + } + else if (!g_spawn_check_exit_status (exit_status, &error)) { - /* Treat failure-to-prompt as user confirmation. - Otherwise how will the user ever log out? */ confirmed = TRUE; } else @@ -698,6 +704,7 @@ zenity_question (IndicatorSessionActionsDbus * self, confirmed = exit_status == 0; } + log_and_clear_error (&error, G_STRLOC, G_STRFUNC); g_free (command_line); return confirmed; } -- cgit v1.2.3 From 52d94a51a0a4b8660a63f14e37ddf5183b052b02 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 18 Jun 2014 15:34:50 -0500 Subject: If we try to prompt for confirmation using unity but the EndSessionDialog errors out, treat that as confirmation. Otherwise how will a user ever log out? --- src/backend-dbus/actions.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/backend-dbus/actions.c b/src/backend-dbus/actions.c index 5447440..c19d02a 100644 --- a/src/backend-dbus/actions.c +++ b/src/backend-dbus/actions.c @@ -635,7 +635,17 @@ on_open_end_session_dialog_ready (GObject * o, { GError * err = NULL; end_session_dialog_call_open_finish (END_SESSION_DIALOG(o), res, &err); - log_and_clear_error (&err, G_STRLOC, G_STRFUNC); + if (err != NULL) + { + if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("%s %s: %s", G_STRFUNC, G_STRLOC, err->message); + + /* Treat errors as user confirmation. + Otherwise how will the user ever log out? */ + logout_now(INDICATOR_SESSION_ACTIONS_DBUS(gself)); + + g_clear_error(&err); + } } static void -- cgit v1.2.3