[gnome-packagekit/polkit1: 30/30] Look for PIDs on the session and system busses. Fixes rh#506817
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-packagekit/polkit1: 30/30] Look for PIDs on the session and system busses. Fixes rh#506817
- Date: Mon, 22 Jun 2009 07:37:57 -0400 (EDT)
commit 436fc803e66be7675cfd939aa0555967df0849a0
Author: Richard Hughes <richard hughsie com>
Date: Mon Jun 22 12:36:23 2009 +0100
Look for PIDs on the session and system busses. Fixes rh#506817
src/gpk-dbus.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 73 insertions(+), 12 deletions(-)
---
diff --git a/src/gpk-dbus.c b/src/gpk-dbus.c
index 573b1c0..3991b23 100644
--- a/src/gpk-dbus.c
+++ b/src/gpk-dbus.c
@@ -59,8 +59,8 @@ struct GpkDbusPrivate
gint timeout_tmp;
GpkX11 *x11;
GPtrArray *array;
- DBusGConnection *connection;
- DBusGProxy *proxy_pid;
+ DBusGProxy *proxy_session_pid;
+ DBusGProxy *proxy_system_pid;
};
G_DEFINE_TYPE (GpkDbus, gpk_dbus, G_TYPE_OBJECT)
@@ -103,27 +103,48 @@ gpk_dbus_error_get_type (void)
}
/**
- * gpk_dbus_get_pid:
+ * gpk_dbus_get_pid_session:
**/
static guint
-gpk_dbus_get_pid (GpkDbus *dbus, const gchar *sender)
+gpk_dbus_get_pid_session (GpkDbus *dbus, const gchar *sender)
{
guint pid = G_MAXUINT;
gboolean ret;
GError *error = NULL;
- g_return_val_if_fail (PK_IS_DBUS (dbus), G_MAXUINT);
- g_return_val_if_fail (dbus->priv->proxy_pid != NULL, G_MAXUINT);
- g_return_val_if_fail (sender != NULL, G_MAXUINT);
+ /* get pid from DBus (quite slow) */
+ ret = dbus_g_proxy_call (dbus->priv->proxy_session_pid, "GetConnectionUnixProcessID", &error,
+ G_TYPE_STRING, sender,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &pid,
+ G_TYPE_INVALID);
+ if (!ret) {
+ egg_debug ("failed to get pid from session: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+out:
+ return pid;
+}
+
+/**
+ * gpk_dbus_get_pid_system:
+ **/
+static guint
+gpk_dbus_get_pid_system (GpkDbus *dbus, const gchar *sender)
+{
+ guint pid = G_MAXUINT;
+ gboolean ret;
+ GError *error = NULL;
/* get pid from DBus (quite slow) */
- ret = dbus_g_proxy_call (dbus->priv->proxy_pid, "GetConnectionUnixProcessID", &error,
+ ret = dbus_g_proxy_call (dbus->priv->proxy_system_pid, "GetConnectionUnixProcessID", &error,
G_TYPE_STRING, sender,
G_TYPE_INVALID,
G_TYPE_UINT, &pid,
G_TYPE_INVALID);
if (!ret) {
- egg_warning ("failed to get pid: %s", error->message);
+ egg_debug ("failed to get pid from system: %s", error->message);
g_error_free (error);
goto out;
}
@@ -131,6 +152,35 @@ out:
return pid;
}
+/**
+ * gpk_dbus_get_pid:
+ **/
+static guint
+gpk_dbus_get_pid (GpkDbus *dbus, const gchar *sender)
+{
+ guint pid;
+
+ g_return_val_if_fail (PK_IS_DBUS (dbus), G_MAXUINT);
+ g_return_val_if_fail (dbus->priv->proxy_session_pid != NULL, G_MAXUINT);
+ g_return_val_if_fail (dbus->priv->proxy_system_pid != NULL, G_MAXUINT);
+ g_return_val_if_fail (sender != NULL, G_MAXUINT);
+
+ /* check system bus first */
+ pid = gpk_dbus_get_pid_system (dbus, sender);
+ if (pid != G_MAXUINT)
+ goto out;
+
+ /* and then session bus */
+ pid = gpk_dbus_get_pid_session (dbus, sender);
+ if (pid != G_MAXUINT)
+ goto out;
+
+ /* should be impossible */
+ egg_warning ("could not find pid!");
+out:
+ return pid;
+}
+
/**
* gpk_dbus_get_exec_for_sender:
@@ -437,13 +487,23 @@ gpk_dbus_class_init (GpkDbusClass *klass)
static void
gpk_dbus_init (GpkDbus *dbus)
{
+ DBusGConnection *connection;
+
dbus->priv = GPK_DBUS_GET_PRIVATE (dbus);
dbus->priv->timeout_tmp = -1;
dbus->priv->gconf_client = gconf_client_get_default ();
dbus->priv->array = g_ptr_array_new ();
dbus->priv->x11 = gpk_x11_new ();
- dbus->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
- dbus->priv->proxy_pid = dbus_g_proxy_new_for_name_owner (dbus->priv->connection,
+
+ /* find out PIDs on the session bus */
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+ dbus->priv->proxy_session_pid = dbus_g_proxy_new_for_name_owner (connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus/Bus",
+ "org.freedesktop.DBus", NULL);
+ /* find out PIDs on the system bus */
+ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+ dbus->priv->proxy_system_pid = dbus_g_proxy_new_for_name_owner (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus/Bus",
"org.freedesktop.DBus", NULL);
@@ -465,7 +525,8 @@ gpk_dbus_finalize (GObject *object)
g_ptr_array_free (dbus->priv->array, TRUE);
g_object_unref (dbus->priv->gconf_client);
g_object_unref (dbus->priv->x11);
- g_object_unref (dbus->priv->proxy_pid);
+ g_object_unref (dbus->priv->proxy_session_pid);
+ g_object_unref (dbus->priv->proxy_system_pid);
G_OBJECT_CLASS (gpk_dbus_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]