From b82eff1c72c609902a87d6fb05a2f8fd17070e35 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 30 May 2020 17:51:45 +1000 Subject: [PATCH] Add SIGTERM handler --- MD_Init.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MD_Init.c b/MD_Init.c index c43c0d8..0d997b5 100644 --- a/MD_Init.c +++ b/MD_Init.c @@ -3,6 +3,7 @@ #include #else #include +#include #endif #include #include @@ -172,6 +173,16 @@ int read_doorsys(const char *dropfile) { return 0; } +#if !defined(WIN32) && !defined(_MSC_VER) + +void md_sigtermhandler(int i) +{ + md_exit(-1); +} + +#endif + + void md_exit(int exitcode) { if (mdcontrol.socket == -1) { #if !defined(WIN32) && !defined(_MSC_VER) @@ -187,6 +198,8 @@ void md_init(const char *dropfile, int socket) { char *filename = strrchr(dropfile, PATH_SEP); #if !defined(WIN32) && !defined(_MSC_VER) struct termios ttystate; + signal(SIGTERM, &md_sigtermhandler); + #endif int ret = -1;