try again again

This commit is contained in:
Andrew Pamment 2016-08-07 16:00:37 +10:00
parent 2f81bae845
commit 1a4a16825f
2 changed files with 20 additions and 8 deletions

17
bbs.c
View File

@ -26,6 +26,15 @@ int timeoutpaused;
char *ipaddress; char *ipaddress;
void sigterm_handler(int s)
{
if (mynode != 0) {
disconnect("Terminated.");
}
exit(0);
}
void dolog(char *fmt, ...) { void dolog(char *fmt, ...) {
char buffer[512]; char buffer[512];
struct tm time_now; struct tm time_now;
@ -487,6 +496,7 @@ void runbbs_real(int socket, char *ip, int ssh) {
time_t now; time_t now;
struct itimerval itime; struct itimerval itime;
struct sigaction sa; struct sigaction sa;
struct sigaction st;
lua_State *L; lua_State *L;
int do_internal_login = 0; int do_internal_login = 0;
@ -501,7 +511,12 @@ void runbbs_real(int socket, char *ip, int ssh) {
sshBBS = 1; 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; gSocket = socket;

5
main.c
View File

@ -28,7 +28,6 @@
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
extern int mynode;
int ssh_pid = -1; int ssh_pid = -1;
@ -604,9 +603,7 @@ void serverssh(int port) {
} }
ssh_disconnect(p_ssh_session); ssh_disconnect(p_ssh_session);
ssh_finalize(); ssh_finalize();
if (mynode != 0) { kill(bbs_pid, SIGTERM);
disconnect("Channel Closed");
}
exit(0); exit(0);
} else if (pid > 0) { } else if (pid > 0) {