From 963c8e4f95f0a6b9f7a6bffa414d20692bde4fb1 Mon Sep 17 00:00:00 2001 From: Emil Ivanichkov Date: Fri, 22 Mar 2024 14:23:39 +0200 Subject: [PATCH] feat(SNM): Handle `Ctr+C` command --- src/status_node_manager.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/status_node_manager.nim b/src/status_node_manager.nim index 01b491f..ec3dedb 100644 --- a/src/status_node_manager.nim +++ b/src/status_node_manager.nim @@ -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()