1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-09-17 14:57:22 +03:00

boot/init: Harmonized failure methods

- Code is now more of a title
 - Only one code path exists to the applet
This commit is contained in:
Samuel Dionne-Riel 2020-11-08 17:25:24 -05:00
parent e6778f8370
commit aa1c2f3744
4 changed files with 83 additions and 31 deletions

View File

@ -39,26 +39,14 @@ Tasks::Modules.new(*Configuration["kernel"]["modules"])
Tasks::go()
$logger.fatal("Tasks all ran, but we're still here...")
System.failure("did_not_switch", color: "ff0000")
System.failure(
"Boot process failed to switch to stage-2",
"The stage-1 init did not detect any failure condition, but failed to switch to stage-2.\n\n" +
"It shouldn't happen, yet here we are.",
color: "ff0000"
)
rescue => e
System.sad_phone("765300", "Uncaught Exception", e.inspect)
3.times do
$logger.fatal("********************")
end
$logger.fatal("Handling exception")
$logger.fatal(e.inspect)
$logger.fatal("`init` will exit and the kernel will crash.")
$logger.fatal("********************")
# Leave some time for the $logger.fatals to flush before the kernel crashes.
sleep(1)
System.shell if System.respond_to?(:shell)
# Users with access to serial debug may prefer crashing to the bootloader.
# Though, crashing the kernel is *required* for console ramoops to be present.
if Configuration["boot"]["crashToBootloader"] then
System.run("reboot bootloader")
else
exit 99
end
# Then fail
System.failure("Uncaught Exception", e.inspect, color: "765300", status: 99)
end

View File

@ -169,22 +169,86 @@ module System
end
end
def self.sad_phone(color, code, message)
def self.failure(code, message="(No details given)", color: "000000", delay: Configuration["boot"]["fail"]["delay"], status: 111)
Progress.kill()
# First print the error we're handling.
# The added asterisks seve to aid in finding it visually.
5.times do
$logger.fatal("********************************************")
end
$logger.fatal("")
$logger.fatal("********************************************")
$logger.fatal("* Fatal error in Mobile NixOS stage-1 init *")
$logger.fatal("********************************************")
$logger.fatal("")
$logger.fatal(code)
$logger.fatal("")
$logger.fatal(message)
$logger.fatal("")
5.times do
$logger.fatal("********************************************")
end
_flush_outputs()
# Show the error handler applet.
begin
System.run(LOADER, "/applets/boot-error.mrb", color, code, message)
rescue CommandError => e
$logger.fatal(e.inspect)
end
# Drop down to a shell if desired.
shell if respond_to?(:shell)
# Both allows the serial output to flush before the kernel panic, and
# allows the failure message to be shown for an amount of time.
sleep(delay)
# User might want to force a reboot, rather than rely on what the kernel is
# configured to do with a kernel panic.
if Configuration["boot"]["fail"]["reboot"]
$logger.fatal("")
$logger.fatal("********************************************")
$logger.fatal("* Forcing a reboot... *")
$logger.fatal("********************************************")
_flush_outputs(true)
hard_reboot
end
if Configuration["boot"]["crashToBootloader"]
$logger.fatal("")
$logger.fatal("********************************************")
$logger.fatal("* Rebooting to bootloader... *")
$logger.fatal("********************************************")
_flush_outputs(true)
# Users with access to serial debug may prefer crashing to the bootloader.
# Though, crashing the kernel is *required* for console ramoops to be present.
System.run("reboot bootloader")
end
$logger.fatal("")
$logger.fatal("********************************************")
$logger.fatal("* init will now exit and crash the system *")
$logger.fatal("********************************************")
_flush_outputs(true)
exit status
end
def self.failure(code, message="(No details given)", color: "000000", delay: Configuration["boot"]["fail"]["delay"])
Progress.kill()
$logger.fatal("#{code}: #{message}")
sad_phone(color, code, message)
shell if respond_to?(:shell)
sleep(delay)
hard_reboot if Configuration["boot"]["fail"]["reboot"]
exit 111
# Flushes the outputs.
# Optionally sleep to give time for the kernel to write the output.
def self._flush_outputs(with_sleep = false)
# Flush both output
$stdout.flush
$stderr.flush
sleep(1) if with_sleep
end
def self.hard_reboot()

View File

@ -92,7 +92,7 @@ module Tasks
"\n"
# Fail with a black backdrop, and force the message to stay up 60s
System.failure("hung_tasks", msg, color: "000000", delay: 60)
System.failure("Hung Tasks", msg, color: "000000", delay: 60)
end
# Don't burn the CPU if we're waiting on something...

View File

@ -77,7 +77,7 @@ class Tasks::SwitchRoot < SingletonTask
return path if path
end
System.failure("init_not_found", "Could not find init path for stage-2", color: "FF00FF")
System.failure("Stage-2 init not found", "Could not find init path for stage-2", color: "FF00FF")
end
# May pause the boot to allow the user to select a generation.