Minor changes to nimDExit and shutdown.nim

This commit is contained in:
Mattia Giambirtone 2022-03-12 15:51:31 +01:00
parent c0a3c18140
commit d240d05cef
1 changed files with 4 additions and 5 deletions

View File

@ -32,16 +32,14 @@ type ShutdownHandler* = ref object
const reboot_codes = {"poweroff": 0x4321fedc'i64, "reboot": 0x01234567'i64, "halt": 0xcdef0123}.toTable()
var shutdownHandlers: seq[ShutdownHandler] = @[]
var sigTermDelay: float = 90
proc newShutdownHandler*(body: proc (logger: Logger, code: int)): ShutdownHandler =
result = ShutdownHandler(body: body)
var shutdownHandlers: seq[ShutdownHandler] = @[]
var sigTermDelay: float = 90
proc setSigTermDelay*(delay: int = 90) =
# Sets the sigtermDelay variable
sigTermDelay = float(delay)
@ -97,8 +95,8 @@ proc nimDExit*(logger: Logger, code: int, emerg: bool = true) =
# We're in emergency mode: do not crash the kernel, spawn a shell and exit
logger.fatal("NimD has entered emergency mode and cannot continue. You will be now (hopefully) dropped in a root shell: you're on your own. May the force be with you")
logger.info("Terminating child processes with SIGKILL")
discard execCmd(os.getEnv("SHELL", "/bin/sh")) # TODO: Is this fine? maybe use execProcess
discard posix.kill(-1, SIGKILL)
discard execCmd(os.getEnv("SHELL", "/bin/sh")) # TODO: Is this fine? maybe use execProcess
quit(-1)
logger.warning("The system is shutting down")
logger.info("Processing shutdown runlevel")
@ -121,6 +119,7 @@ proc nimDExit*(logger: Logger, code: int, emerg: bool = true) =
logger.info("Terminating child processes with SIGKILL")
discard posix.kill(-1, SIGKILL)
logger.warning("Shutdown procedure complete, NimD is exiting")
quit(-1)
proc reboot*(logger: Logger) =