launcher: Use $XDG_SESSION_ID if available

In some cases mutter is started in the user scope from a TTY (for
example using toolbox). Using sd_pid_get_session fails because it's not
in the session scope so it falls back to the primary session
(sd_uid_get_display). We want to start mutter on the TTY we started
mutter on however. Instead of relying on the scope to figure out the
correct session we first look at $XDG_SESSION_ID which is set by
systemd_pam.so.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2254>
This commit is contained in:
Sebastian Wick 2022-01-24 17:31:32 +01:00
parent 97257157ba
commit 8ebdae8092

View File

@ -72,10 +72,29 @@ find_systemd_session (gchar **session_id,
g_auto (GStrv) sessions = NULL; g_auto (GStrv) sessions = NULL;
int n_sessions; int n_sessions;
int saved_errno; int saved_errno;
const char *xdg_session_id = NULL;
g_assert (session_id != NULL); g_assert (session_id != NULL);
g_assert (error == NULL || *error == NULL); g_assert (error == NULL || *error == NULL);
xdg_session_id = g_getenv ("XDG_SESSION_ID");
if (xdg_session_id)
{
saved_errno = sd_session_is_active (xdg_session_id);
if (saved_errno < 0)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
"Failed to get status of XDG_SESSION_ID session (%s)",
g_strerror (-saved_errno));
return FALSE;
}
*session_id = g_strdup (xdg_session_id);
return TRUE;
}
/* if we are in a logind session, we can trust that value, so use it. This /* if we are in a logind session, we can trust that value, so use it. This
* happens for example when you run mutter directly from a VT but when * happens for example when you run mutter directly from a VT but when
* systemd starts us we will not be in a logind session. */ * systemd starts us we will not be in a logind session. */