Add SIGTERM handler

This commit is contained in:
Andrew Pamment 2020-05-30 17:51:45 +10:00
parent 160dbcd50f
commit b82eff1c72

View File

@ -3,6 +3,7 @@
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <termios.h> #include <termios.h>
#include <signal.h>
#endif #endif
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -172,6 +173,16 @@ int read_doorsys(const char *dropfile) {
return 0; return 0;
} }
#if !defined(WIN32) && !defined(_MSC_VER)
void md_sigtermhandler(int i)
{
md_exit(-1);
}
#endif
void md_exit(int exitcode) { void md_exit(int exitcode) {
if (mdcontrol.socket == -1) { if (mdcontrol.socket == -1) {
#if !defined(WIN32) && !defined(_MSC_VER) #if !defined(WIN32) && !defined(_MSC_VER)
@ -187,6 +198,8 @@ void md_init(const char *dropfile, int socket) {
char *filename = strrchr(dropfile, PATH_SEP); char *filename = strrchr(dropfile, PATH_SEP);
#if !defined(WIN32) && !defined(_MSC_VER) #if !defined(WIN32) && !defined(_MSC_VER)
struct termios ttystate; struct termios ttystate;
signal(SIGTERM, &md_sigtermhandler);
#endif #endif
int ret = -1; int ret = -1;