- Bring shutdown menu item back. More fallout from my buggy patch

introduced in -7
This commit is contained in:
Ray Strode 2008-10-10 20:43:46 +00:00
parent 0bb290414d
commit 03acb97cd6
2 changed files with 34 additions and 64 deletions

View File

@ -1,37 +1,24 @@
diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-consolekit.c diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-consolekit.c
--- gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400 --- gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
+++ gnome-session-2.24.0/gnome-session/gsm-consolekit.c 2008-10-09 13:30:44.000000000 -0400 +++ gnome-session-2.24.0/gnome-session/gsm-consolekit.c 2008-10-10 16:39:55.000000000 -0400
@@ -54,6 +54,7 @@ struct _GsmConsolekitPrivate @@ -54,6 +54,9 @@ struct _GsmConsolekitPrivate
DBusGConnection *dbus_connection; DBusGConnection *dbus_connection;
DBusGProxy *bus_proxy; DBusGProxy *bus_proxy;
DBusGProxy *ck_proxy; DBusGProxy *ck_proxy;
+ PolKitTracker *pk_tracker; +#ifdef HAVE_POLKIT_GNOME
+ PolKitSession *pk_session;
+#endif
guint32 is_connected : 1; guint32 is_connected : 1;
}; };
@@ -136,15 +137,29 @@ gsm_consolekit_class_init (GsmConsolekit @@ -140,11 +143,14 @@ static gboolean
g_type_class_add_private (manager_class, sizeof (GsmConsolekitPrivate));
}
+static DBusHandlerResult
+filter_function (DBusConnection *connection,
+ DBusMessage *message,
+ GsmConsolekit *manager)
+{
+ if (manager->priv->pk_tracker != NULL) {
+ polkit_tracker_dbus_func (manager->priv->pk_tracker, message);
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
static gboolean
gsm_consolekit_ensure_ck_connection (GsmConsolekit *manager, gsm_consolekit_ensure_ck_connection (GsmConsolekit *manager,
GError **error) GError **error)
{ {
+ DBusConnection *connection; + DBusConnection *connection;
GError *connection_error; GError *connection_error;
gboolean is_connected; gboolean is_connected;
+ const char *cookie;
connection_error = NULL; connection_error = NULL;
@ -39,64 +26,48 @@ diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-ap
if (manager->priv->dbus_connection == NULL) { if (manager->priv->dbus_connection == NULL) {
manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
&connection_error); &connection_error);
@@ -154,6 +169,13 @@ gsm_consolekit_ensure_ck_connection (Gsm @@ -154,6 +160,8 @@ gsm_consolekit_ensure_ck_connection (Gsm
is_connected = FALSE; is_connected = FALSE;
goto out; goto out;
} }
+ +
+ connection = dbus_g_connection_get_connection (manager->priv->dbus_connection); + connection = dbus_g_connection_get_connection (manager->priv->dbus_connection);
+
+ dbus_connection_add_filter (connection,
+ (DBusHandleMessageFunction)
+ filter_function,
+ manager, NULL);
} }
if (manager->priv->bus_proxy == NULL) { if (manager->priv->bus_proxy == NULL) {
@@ -198,6 +220,27 @@ gsm_consolekit_ensure_ck_connection (Gsm @@ -198,6 +206,17 @@ gsm_consolekit_ensure_ck_connection (Gsm
} }
} }
+ if (manager->priv->pk_tracker == NULL && connection != NULL) { +#ifdef HAVE_POLKIT_GNOME
+ PolKitCaller *caller; + cookie = g_getenv ("XDG_SESSION_COOKIE");
+ if (manager->priv->pk_session == NULL && connection != NULL && cookie != NULL) {
+ DBusError error; + DBusError error;
+ +
+ manager->priv->pk_tracker = polkit_tracker_new ();
+ polkit_tracker_init (manager->priv->pk_tracker);
+ polkit_tracker_set_system_bus_connection (manager->priv->pk_tracker,
+ connection);
+
+ /* Prime the tracker's cache
+ */
+ dbus_error_init (&error); + dbus_error_init (&error);
+ caller = polkit_tracker_get_caller_from_dbus_name (manager->priv->pk_tracker, + manager->priv->pk_session = polkit_session_new_from_cookie (connection, cookie, &error);
+ CK_NAME, &error);
+ dbus_error_free (&error); + dbus_error_free (&error);
+
+ if (caller != NULL) {
+ g_object_unref (caller);
+ }
+ } + }
+#endif
+ +
is_connected = TRUE; is_connected = TRUE;
out: out:
@@ -825,20 +868,68 @@ gsm_consolekit_can_switch_user (GsmConso @@ -825,20 +844,62 @@ gsm_consolekit_can_switch_user (GsmConso
return ret; return ret;
} }
+#ifdef HAVE_POLKIT_GNOME
+static gboolean +static gboolean
+gsm_consolekit_can_do_action (GsmConsolekit *manager, +gsm_consolekit_can_do_action (GsmConsolekit *manager,
+ const char *action_name) + const char *action_id)
+{ +{
+ PolKitGnomeContext *gnome_context; + PolKitGnomeContext *gnome_context;
+ PolKitPolicyCache *policy_cache; + PolKitPolicyCache *policy_cache;
+ PolKitPolicyFileEntry *file_entry; + PolKitPolicyFileEntry *file_entry;
+ PolKitPolicyDefault *policy; + PolKitPolicyDefault *policy;
+ PolKitAction *action; + PolKitAction *action;
+ PolKitCaller *caller;
+ PolKitResult result; + PolKitResult result;
+ DBusError error;
+ +
+ gnome_context = polkit_gnome_context_get (NULL); + gnome_context = polkit_gnome_context_get (NULL);
+ +
@ -105,29 +76,24 @@ diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-ap
+ } + }
+ +
+ policy_cache = polkit_context_get_policy_cache (gnome_context->pk_context); + policy_cache = polkit_context_get_policy_cache (gnome_context->pk_context);
+ file_entry = polkit_policy_cache_get_entry_by_id (policy_cache, "org.freedesktop.consolekit"); + file_entry = polkit_policy_cache_get_entry_by_id (policy_cache, action_id);
+ policy = polkit_policy_file_entry_get_default (file_entry); + policy = polkit_policy_file_entry_get_default (file_entry);
+ action = polkit_action_new (); + action = polkit_action_new ();
+ if (polkit_action_set_action_id (action, action_name)) { + if (!polkit_action_set_action_id (action, action_id)) {
+ polkit_action_unref (action); + polkit_action_unref (action);
+ return FALSE; + return FALSE;
+ } + }
+ +
+ dbus_error_init (&error); + result = POLKIT_RESULT_UNKNOWN;
+ caller = + if (manager->priv->pk_session != NULL) {
+ polkit_tracker_get_caller_from_dbus_name (manager->priv->pk_tracker, + result = polkit_policy_default_can_session_do_action (policy,
+ CK_NAME, &error);
+ dbus_error_free (&error);
+
+ if (caller != NULL) {
+ result = polkit_policy_default_can_caller_do_action (policy,
+ action, + action,
+ caller); + manager->priv->pk_session);
+ polkit_caller_unref (caller);
+ } + }
+ +
+ return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN; + return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
+} +}
+#endif
+ +
gboolean gboolean
gsm_consolekit_can_restart (GsmConsolekit *manager) gsm_consolekit_can_restart (GsmConsolekit *manager)
@ -151,7 +117,7 @@ diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-ap
#else #else
g_debug ("GsmConsolekit: built without PolicyKit-gnome support - cannot restart system"); g_debug ("GsmConsolekit: built without PolicyKit-gnome support - cannot restart system");
return FALSE; return FALSE;
@@ -857,8 +948,11 @@ gsm_consolekit_can_stop (GsmConsolekit * @@ -857,8 +918,11 @@ gsm_consolekit_can_stop (GsmConsolekit *
g_warning ("Could not connect to ConsoleKit: %s", g_warning ("Could not connect to ConsoleKit: %s",
error->message); error->message);
g_error_free (error); g_error_free (error);
@ -166,7 +132,7 @@ diff -up gnome-session-2.24.0/gnome-session/gsm-consolekit.c.add-can-shutdown-ap
return FALSE; return FALSE;
diff -up gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-manager.c diff -up gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-manager.c
--- gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400 --- gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
+++ gnome-session-2.24.0/gnome-session/gsm-manager.c 2008-10-09 13:10:23.000000000 -0400 +++ gnome-session-2.24.0/gnome-session/gsm-manager.c 2008-10-10 16:16:17.000000000 -0400
@@ -2313,6 +2313,35 @@ gsm_manager_shutdown (GsmManager *manage @@ -2313,6 +2313,35 @@ gsm_manager_shutdown (GsmManager *manage
} }
@ -205,7 +171,7 @@ diff -up gnome-session-2.24.0/gnome-session/gsm-manager.c.add-can-shutdown-api g
GError **error) GError **error)
diff -up gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-manager.h diff -up gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api gnome-session-2.24.0/gnome-session/gsm-manager.h
--- gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400 --- gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
+++ gnome-session-2.24.0/gnome-session/gsm-manager.h 2008-10-09 13:10:23.000000000 -0400 +++ gnome-session-2.24.0/gnome-session/gsm-manager.h 2008-10-10 16:16:17.000000000 -0400
@@ -151,6 +151,10 @@ gboolean gsm_manager_is_inhib @@ -151,6 +151,10 @@ gboolean gsm_manager_is_inhib
gboolean gsm_manager_shutdown (GsmManager *manager, gboolean gsm_manager_shutdown (GsmManager *manager,
@ -219,7 +185,7 @@ diff -up gnome-session-2.24.0/gnome-session/gsm-manager.h.add-can-shutdown-api g
GError **error); GError **error);
diff -up gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml.add-can-shutdown-api gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml diff -up gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml.add-can-shutdown-api gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml
--- gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400 --- gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml.add-can-shutdown-api 2008-09-22 17:21:08.000000000 -0400
+++ gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml 2008-10-09 14:33:59.000000000 -0400 +++ gnome-session-2.24.0/gnome-session/org.gnome.SessionManager.xml 2008-10-10 16:16:17.000000000 -0400
@@ -252,6 +252,20 @@ @@ -252,6 +252,20 @@
</doc:doc> </doc:doc>
</method> </method>

View File

@ -12,7 +12,7 @@
Summary: GNOME session manager Summary: GNOME session manager
Name: gnome-session Name: gnome-session
Version: 2.24.0 Version: 2.24.0
Release: 8%{?dist} Release: 9%{?dist}
URL: http://www.gnome.org URL: http://www.gnome.org
Source0: http://download.gnome.org/sources/gnome-session/2.24/%{name}-%{version}.tar.bz2 Source0: http://download.gnome.org/sources/gnome-session/2.24/%{name}-%{version}.tar.bz2
Source1: redhat-default-session Source1: redhat-default-session
@ -196,6 +196,10 @@ fi
%changelog %changelog
* Fri Oct 10 2008 Ray Strode <rstrode@redhat.com> - 2.24.0-9
- Bring shutdown menu item back. More fallout from my buggy
patch introduced in -7
* Thu Oct 9 2008 Ray Strode <rstrode@redhat.com> - 2.24.0-8 * Thu Oct 9 2008 Ray Strode <rstrode@redhat.com> - 2.24.0-8
- Fix assertion failure in last patch - Fix assertion failure in last patch