feat(SNM): Handle `Ctr+C` command

This commit is contained in:
Emil Ivanichkov 2024-03-22 14:23:39 +02:00 committed by Emil Ivanichkov
parent 81a6da009a
commit 963c8e4f95
1 changed files with 14 additions and 0 deletions

View File

@ -67,6 +67,20 @@ proc doRunStatusNodeManager*(config: StatusNodeManagerConfig,
rng: ref HmacDrbgContext) =
notice "Starting Status Node Manager"
## Ctrl+C handling
proc controlCHandler() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057
try:
setupForeignThreadGc()
except Exception as exc: raiseAssert exc.msg # shouldn't happen
notice "Shutting down after having received SIGINT"
snmStatus = SNMStatus.Stopping
try:
setControlCHook(controlCHandler)
except Exception as exc: # TODO Exception
warn "Cannot set ctrl-c handler", msg = exc.msg
let snm = waitFor SNM.init(rng, config)
waitFor snm.run()