summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2020-01-23 14:32:38 +0100
committerBenjamin Berg <benjamin@sipsolutions.net>2020-04-22 18:23:38 +0000
commit32646105196ed7a687f3684b69ea544dd01d2ade (patch)
tree533efaf263b7447174f1ffa4d380b16994d18815 /common
parent2090685406c775d734d57b40f84bd0876a9e829e (diff)
downloadgdm-32646105196ed7a687f3684b69ea544dd01d2ade.tar.gz
manager: Try looking up session based on PID first
Unfortunately, GDM may be running multiple greeters, and each greeter is currently using the same user. So while in a lot of setups each user should only have one graphical session and also only one DBus session bus, this is not true for the gdm greeter. Lacking another solution (e.g. separate users), we need to be able to correctly lookup the session information for all greeter instances. We can do so by using sd_pid_get_session and using this information is safe if it does return something. See: #526
Diffstat (limited to 'common')
-rw-r--r--common/gdm-common.c30
-rw-r--r--common/gdm-common.h7
2 files changed, 30 insertions, 7 deletions
diff --git a/common/gdm-common.c b/common/gdm-common.c
index 41bdb389..b8de7555 100644
--- a/common/gdm-common.c
+++ b/common/gdm-common.c
@@ -497,7 +497,7 @@ goto_login_session (GDBusConnection *connection,
* since the data allocated is from libsystemd-logind, which
* does not use GLib's g_malloc (). */
- if (!gdm_find_display_session_for_uid (getuid (), &our_session, &local_error)) {
+ if (!gdm_find_display_session (0, getuid (), &our_session, &local_error)) {
g_propagate_prefixed_error (error, local_error, _("Could not identify the current session: "));
return FALSE;
@@ -898,16 +898,38 @@ _systemd_session_is_active (const char *session_id)
}
gboolean
-gdm_find_display_session_for_uid (const uid_t uid,
- char **out_session_id,
- GError **error)
+gdm_find_display_session (GPid pid,
+ const uid_t uid,
+ char **out_session_id,
+ GError **error)
{
char *local_session_id = NULL;
g_auto(GStrv) sessions = NULL;
int n_sessions;
+ int res;
g_return_val_if_fail (out_session_id != NULL, FALSE);
+ /* First try to look up the session using the pid. We need this
+ * at least for the greeter, because it currently runs multiple
+ * sessions under the same user.
+ * See also commit 2b52d8933c8ab38e7ee83318da2363d00d8c5581
+ * which added an explicit dbus-run-session for all but seat0.
+ */
+ res = sd_pid_get_session (pid, &local_session_id);
+ if (res >= 0) {
+ g_debug ("GdmCommon: Found session %s for PID %d, using", local_session_id, pid);
+
+ *out_session_id = g_strdup (local_session_id);
+ free (local_session_id);
+
+ return TRUE;
+ } else {
+ if (res != -ENODATA)
+ g_warning ("GdmCommon: Failed to retrieve session information for pid %d: %s",
+ pid, strerror (-res));
+ }
+
g_debug ("Finding a graphical session for user %d", uid);
n_sessions = sd_uid_get_sessions (uid,
diff --git a/common/gdm-common.h b/common/gdm-common.h
index 5c3fe137..001b70c1 100644
--- a/common/gdm-common.h
+++ b/common/gdm-common.h
@@ -51,9 +51,10 @@ int gdm_wait_on_and_disown_pid (int pid,
int gdm_signal_pid (int pid,
int signal);
-gboolean gdm_find_display_session_for_uid (const uid_t uid,
- char **out_session_id,
- GError **error);
+gboolean gdm_find_display_session (GPid pid,
+ const uid_t uid,
+ char **out_session_id,
+ GError **error);
gboolean gdm_get_pwent_for_name (const char *name,
struct passwd **pwentp);