From 89162a90aadce266a17fc67aa03162e473adb2e0 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Mon, 9 Jul 2018 10:20:47 +0100 Subject: [PATCH] launcher: First check if we are in a login session For mutter developers we still want to support running from a VT, which will be in a different login session. Fixes #218 --- src/backends/native/meta-launcher.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/backends/native/meta-launcher.c b/src/backends/native/meta-launcher.c index 15cad0d40..fb12b0cf5 100644 --- a/src/backends/native/meta-launcher.c +++ b/src/backends/native/meta-launcher.c @@ -79,6 +79,29 @@ find_systemd_session (gchar **session_id, g_assert (session_id != NULL); g_assert (error == NULL || *error == NULL); + /* 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 + * systemd starts us we will not be in a logind session. */ + saved_errno = sd_pid_get_session (0, &local_session_id); + if (saved_errno < 0) + { + if (saved_errno != -ENODATA) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_NOT_FOUND, + "Failed to get session by pid for user %d (%s)", + getuid (), + g_strerror (-saved_errno)); + return FALSE; + } + } + else + { + *session_id = g_steal_pointer (&local_session_id); + return TRUE; + } + saved_errno = sd_uid_get_display (getuid (), &local_session_id); if (saved_errno < 0) {