From a3d7239895d7055df7a65fddeaffa570fcc3f5ec Mon Sep 17 00:00:00 2001 From: Ruakij Date: Tue, 7 Dec 2021 14:42:37 +0100 Subject: [PATCH] Change shutdown to accept exitCode and kill-signal --- src/main.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index e41f35e..18f6fa1 100644 --- a/src/main.js +++ b/src/main.js @@ -117,15 +117,20 @@ if(errorMsg){ loggerTcpdump.debug(`tcpdump exited code: ${code}`); if (code) { loggerTcpdump.fatal(`tcpdump exited with non-zero code: ${code}`); - exit(1); + if(!exitCode) exitCode = 1; // When exitCode is 0, set to 1 } logger.info("Shutdown"); - exit(0); + exit(exitCode); }); // Handle stop-signals for graceful shutdown + var exitCode = 0; function shutdownReq() { logger.info("Shutdown request received.."); + shutdown(); + } + function shutdown(code, signal = "SIGTERM"){ + if(code) exitCode = code; logger.debug("Stopping subprocess tcpdump, then exiting myself.."); proc.kill(); // Kill process (send SIGTERM), then upper event-handler will stop self }