From 1a4a16825f42b60df6b0a30fed6138d5a2a6846f Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 7 Aug 2016 16:00:37 +1000 Subject: [PATCH] try again again --- bbs.c | 23 +++++++++++++++++++---- main.c | 5 +---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bbs.c b/bbs.c index e0a660b..c62cd3e 100644 --- a/bbs.c +++ b/bbs.c @@ -24,8 +24,17 @@ int sshBBS; int usertimeout; int timeoutpaused; -char *ipaddress; - +char *ipaddress; + +void sigterm_handler(int s) +{ + if (mynode != 0) { + disconnect("Terminated."); + } + exit(0); +} + + void dolog(char *fmt, ...) { char buffer[512]; struct tm time_now; @@ -486,7 +495,8 @@ void runbbs_real(int socket, char *ip, int ssh) { struct tm oldtime; time_t now; struct itimerval itime; - struct sigaction sa; + struct sigaction sa; + struct sigaction st; lua_State *L; int do_internal_login = 0; @@ -501,7 +511,12 @@ void runbbs_real(int socket, char *ip, int ssh) { sshBBS = 1; } - + st.sa_handler = sigterm_handler; + sigemptyset(&st.sa_mask); + if (sigaction(SIGTERM, &st, NULL) == -1) { + dolog("Failed to setup sigterm handler."); + exit(1); + } gSocket = socket; diff --git a/main.c b/main.c index 5d318f9..ef10e54 100644 --- a/main.c +++ b/main.c @@ -28,7 +28,6 @@ extern struct bbs_config conf; extern struct user_record *gUser; -extern int mynode; int ssh_pid = -1; @@ -604,9 +603,7 @@ void serverssh(int port) { } ssh_disconnect(p_ssh_session); ssh_finalize(); - if (mynode != 0) { - disconnect("Channel Closed"); - } + kill(bbs_pid, SIGTERM); exit(0); } else if (pid > 0) {