fix(linux): explain a missing graphical session when no capture method starts (#6095)

This commit is contained in:
Eren Çakar authored and GitHub committed 2026-11-13 18:12:25 -05:00
1 parent 949570130b
commit 657f9b68bf
3 files changed
+56

No files matched your search

+15
View File
@@ -198,6 +198,20 @@ namespace platf {
return true;
}
bool log_missing_graphical_session_hint() {
// KMS capture runs without a session, so the hint does not apply to it.
if (std::string value; config::video.capture == "kms" || lizardbyte::common::get_env("WAYLAND_DISPLAY", value) || lizardbyte::common::get_env("DISPLAY", value)) {
return false;
}
// Without a session the encoder probe fails too, and its final message
// points at the display instead of at the missing session.
BOOST_LOG(error) << "Neither WAYLAND_DISPLAY nor DISPLAY is set, so Sunshine is not running inside a graphical session. "sv
<< "If it runs as a systemd user service, make sure the session exports its environment to systemd, "sv
<< "for example with \"systemctl --user import-environment WAYLAND_DISPLAY DISPLAY\"."sv;
return true;
}
/**
* @brief Owning pointer for `getifaddrs` results.
*/
@@ -1500,6 +1514,7 @@ namespace platf {
if (sources.none()) {
BOOST_LOG(error) << "Unable to initialize capture method"sv;
log_missing_graphical_session_hint();
return nullptr;
}
+11
View File
@@ -121,6 +121,17 @@ namespace platf {
*/
bool sanitize_process_environment();
/**
* @brief Log a hint when no graphical session is visible to Sunshine.
*
* Called after every capture method failed to initialize. When neither `WAYLAND_DISPLAY` nor `DISPLAY` is set
* and the configured capture method is not KMS, an error explains that Sunshine is not running inside a
* graphical session and how to export the session environment to systemd.
*
* @return `true` when the hint was logged; `false` when a session variable is set or KMS capture is configured.
*/
bool log_missing_graphical_session_hint();
/**
* @brief Open a DRM card node and drop implicit DRM master, if any.
*
+30
View File
@@ -7,6 +7,7 @@
// test includes
#include "../../../tests_common.h"
#include "../../../tests_log_checker.h"
// standard includes
#include <array>
@@ -15,8 +16,10 @@
#include <string>
// local includes
#include "src/config.h"
#include "src/logging.h"
#include "src/platform/linux/misc.h"
#include "src/utility.h"
namespace {
/**
@@ -109,4 +112,31 @@ TEST_F(ProcessEnvironmentSecurity, PreservesTraySessionVariables) {
EXPECT_STREQ(std::getenv("WAYLAND_DISPLAY"), "wayland-test");
}
TEST(LinuxCaptureSessionHint, LogsOnlyWithoutSessionVariablesAndWithoutKms) {
logging::log_flush();
environment_guard_t wayland_guard {"WAYLAND_DISPLAY"};
environment_guard_t display_guard {"DISPLAY"};
const auto original_capture = config::video.capture;
auto restore_capture = util::fail_guard([&]() {
config::video.capture = original_capture;
});
ASSERT_EQ(unsetenv("WAYLAND_DISPLAY"), 0);
ASSERT_EQ(unsetenv("DISPLAY"), 0);
for (const char *capture : {"", "kwin", "kms"}) {
config::video.capture = capture;
EXPECT_EQ(platf::log_missing_graphical_session_hint(), config::video.capture != "kms") << capture;
}
EXPECT_TRUE(log_checker::line_contains("test_sunshine.log", "Error: Neither WAYLAND_DISPLAY nor DISPLAY is set"));
config::video.capture = "kwin";
ASSERT_EQ(setenv("WAYLAND_DISPLAY", "wayland-test", 1), 0);
EXPECT_FALSE(platf::log_missing_graphical_session_hint());
ASSERT_EQ(unsetenv("WAYLAND_DISPLAY"), 0);
ASSERT_EQ(setenv("DISPLAY", ":1", 1), 0);
EXPECT_FALSE(platf::log_missing_graphical_session_hint());
}
#endif // __linux__