From 67d0f5686dc743cf6bbf11b4c61e566b5c3da3c3 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 14 Oct 2022 14:43:40 +0300 Subject: [PATCH] SystemServer: Make system-mode=text the default in case of read failure In case of failure when trying to read the system_mode global node, just use as a default the text mode, so we have bootable system with degraded functionality. --- Userland/Services/SystemServer/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Userland/Services/SystemServer/main.cpp b/Userland/Services/SystemServer/main.cpp index dc191258a8..67b6b9e32c 100644 --- a/Userland/Services/SystemServer/main.cpp +++ b/Userland/Services/SystemServer/main.cpp @@ -64,20 +64,28 @@ static void sigchld_handler(int) static ErrorOr determine_system_mode() { + ArmedScopeGuard declare_text_mode_on_failure([&] { + // Note: Only if the mode is not set to self-test, degrade it to text mode. + if (g_system_mode != "self-test") + g_system_mode = "text"; + }); + auto f = Core::File::construct("/proc/system_mode"); if (!f->open(Core::OpenMode::ReadOnly)) { dbgln("Failed to read system_mode: {}", f->error_string()); - // Continue to assume "graphical". + // Continue and assume "text" mode. return {}; } const String system_mode = String::copy(f->read_all(), Chomp); if (f->error()) { dbgln("Failed to read system_mode: {}", f->error_string()); - // Continue to assume "graphical". + // Continue and assume "text" mode. return {}; } g_system_mode = system_mode; + declare_text_mode_on_failure.disarm(); + dbgln("Read system_mode: {}", g_system_mode); struct stat file_state;