summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-11-07 15:57:50 -0500
committerColin Walters <walters@verbum.org>2013-11-11 18:29:54 -0500
commit26d0c0578211fb96fc8fe75572aa11ad6ecbf9b8 (patch)
treeef1dfe547a330e1166eb7be52ba9c8553b324d8e
parent145d43b9c891f248ad68ebe597cb151a865bdb3a (diff)
downloadpolkit-26d0c0578211fb96fc8fe75572aa11ad6ecbf9b8.tar.gz
sessionmonitor-systemd: Deduplicate code paths
We had the code to go from pid -> session duplicated. If we have a PolkitSystemBusName, convert it to a PolkitUnixProcess. Then we can do PolkitUnixProcess -> pid -> session in one place. This is just a code cleanup. https://bugs.freedesktop.org/show_bug.cgi?id=69538
-rw-r--r--src/polkitbackend/polkitbackendsessionmonitor-systemd.c63
1 files changed, 22 insertions, 41 deletions
diff --git a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c
index 0185310..756b728 100644
--- a/src/polkitbackend/polkitbackendsessionmonitor-systemd.c
+++ b/src/polkitbackend/polkitbackendsessionmonitor-systemd.c
@@ -313,61 +313,42 @@ polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMoni
PolkitSubject *subject,
GError **error)
{
- PolkitSubject *session;
-
- session = NULL;
+ PolkitUnixProcess *tmp_process = NULL;
+ PolkitUnixProcess *process = NULL;
+ PolkitSubject *session = NULL;
+ char *session_id = NULL;
+ pid_t pid;
if (POLKIT_IS_UNIX_PROCESS (subject))
- {
- gchar *session_id;
- pid_t pid;
-
- pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
- if (sd_pid_get_session (pid, &session_id) < 0)
- goto out;
-
- session = polkit_unix_session_new (session_id);
- free (session_id);
- }
+ process = POLKIT_UNIX_PROCESS (subject); /* We already have a process */
else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
{
- guint32 pid;
- gchar *session_id;
- GVariant *result;
-
- result = g_dbus_connection_call_sync (monitor->system_bus,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "GetConnectionUnixProcessID",
- g_variant_new ("(s)", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject))),
- G_VARIANT_TYPE ("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1, /* timeout_msec */
- NULL, /* GCancellable */
- error);
- if (result == NULL)
- goto out;
- g_variant_get (result, "(u)", &pid);
- g_variant_unref (result);
-
- if (sd_pid_get_session (pid, &session_id) < 0)
- goto out;
-
- session = polkit_unix_session_new (session_id);
- free (session_id);
+ /* Convert bus name to process */
+ tmp_process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error);
+ if (!tmp_process)
+ goto out;
+ process = tmp_process;
}
else
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_NOT_SUPPORTED,
- "Cannot get user for subject of type %s",
+ "Cannot get session for subject of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (subject)));
}
- out:
+ /* Now do process -> pid -> session */
+ g_assert (process != NULL);
+ pid = polkit_unix_process_get_pid (process);
+ if (sd_pid_get_session (pid, &session_id) < 0)
+ goto out;
+
+ session = polkit_unix_session_new (session_id);
+ free (session_id);
+ out:
+ if (tmp_process) g_object_unref (tmp_process);
return session;
}