1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-18 05:21:47 +03:00
mobile-nixos/boot/init/tasks/splash.rb
Samuel Dionne-Riel 812b02dd32 boot/init: Fix partial teardown for splash
`#quit` would leave the `@pid` variable around, which in turn meant that
calling `#kill` after would fail since the process was already gone.
2020-12-27 17:50:30 -05:00

53 lines
1.3 KiB
Ruby

# Adds a minimal set of files required for logging-in.
class Tasks::Splash < SingletonTask
def initialize()
add_dependency(:Target, :Graphics)
add_dependency(:Task, Tasks::ProgressSocket.instance)
end
def run()
args = []
if LOG_LEVEL == Logger::DEBUG
args << "--verbose"
end
begin
@pid = System.spawn(LOADER, "/applets/boot-splash.mrb", *args)
# Don't fail the boot if the splash fails
rescue System::CommandError
end
end
def ux_priority()
-100
end
# Implementation details-y; ask for the splash applet to be exited.
def quit(reason)
# Ensures the progress is shown
Progress.update({progress: 100, label: reason})
# Command it to quit
Progress.update({command: {name: "quit"}})
# Ensures that if for any reason the splash didn't start in time for the
# socket to listen to this message, that we'll be quitting it.
loop do
# Repeatedly send the current state (which has the quit command).
Progress.send_state()
# If it has quit, break out!
break if Process.wait(@pid, Process::WNOHANG)
# Leave some breathing room to the CPU!
sleep(0.1)
end
@pid = nil
end
# Use `quit` rather than kill!
def kill()
System.run("kill", "-9", @pid.to_s) if @pid
end
end