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) {