Added reason for disconnect, fixed minix EINTR during accept

This commit is contained in:
Andrew Pamment 2016-08-01 12:03:46 +00:00
parent c7046a66f3
commit b48c0df31a
7 changed files with 25 additions and 19 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ last10.dat
ansis/*
config/*
illusion/*
scripts/*
logs/*
*.a
lua/lua

28
bbs.c
View File

@ -119,7 +119,7 @@ void timer_handler(int signum) {
if (gUser->timeleft <= 0) {
s_putstring(gSocket, "\r\n\r\nSorry, you're out of time today..\r\n");
disconnect(gSocket);
disconnect(gSocket, "Out of Time");
}
@ -129,7 +129,7 @@ void timer_handler(int signum) {
}
if (usertimeout <= 0) {
s_putstring(gSocket, "\r\n\r\nTimeout waiting for input..\r\n");
disconnect(gSocket);
disconnect(gSocket, "Timeout");
}
}
}
@ -464,24 +464,24 @@ char s_getchar(int socket) {
len = read(socket, &c, 1);
if (len == 0) {
disconnect(socket);
disconnect(socket, "Socket Closed");
}
while (c == 255) {
len = read(socket, &c, 1);
if (len == 0) {
disconnect(socket);
disconnect(socket, "Socket Closed");
} else if (c == 255) {
usertimeout = 10;
return c;
}
len = read(socket, &c, 1);
if (len == 0) {
disconnect(socket);
disconnect(socket, "Socket Closed");
}
len = read(socket, &c, 1);
if (len == 0) {
disconnect(socket);
disconnect(socket, "Socket Closed");
}
}
@ -489,7 +489,7 @@ char s_getchar(int socket) {
if (c == '\r') {
if (len == 0) {
disconnect(socket);
disconnect(socket, "Socket Closed");
}
}
} while (c == '\n');
@ -551,12 +551,12 @@ void s_readpass(int socket, char *buffer, int max) {
}
}
void disconnect(int socket) {
void disconnect(int socket, char *calledby) {
char buffer[256];
if (gUser != NULL) {
save_user(gUser);
}
dolog("Node %d disconnected", mynode);
dolog("Node %d disconnected (%s)", mynode, calledby);
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
remove(buffer);
close(socket);
@ -842,8 +842,6 @@ void runbbs(int socket, char *config_path, char *ip) {
s_displayansi(socket, "issue");
s_putstring(socket, "\e[0mEnter your Login Name or NEW to create an account\r\n");
s_putstring(socket, "Login:> ");
@ -857,7 +855,7 @@ void runbbs(int socket, char *config_path, char *ip) {
user = check_user_pass(socket, buffer, password);
if (user == NULL) {
s_putstring(socket, "\r\nIncorrect Login.\r\n");
disconnect(socket);
disconnect(socket, "Incorrect Login");
}
for (i=1;i<=conf.nodes;i++) {
@ -866,14 +864,14 @@ void runbbs(int socket, char *config_path, char *ip) {
nodefile = fopen(buffer, "r");
if (!nodefile) {
printf("Error opening nodefile!\n");
disconnect(socket);
disconnect(socket, "Error opening nodefile!");
}
fgets(buffer, 256, nodefile);
if (strcasecmp(user->loginname, buffer) == 0) {
fclose(nodefile);
s_putstring(socket, "\r\nYou are already logged in.\r\n");
disconnect(socket);
disconnect(socket, "Already Logged in");
}
fclose(nodefile);
}
@ -966,5 +964,5 @@ void runbbs(int socket, char *config_path, char *ip) {
s_displayansi(socket, "goodbye");
dolog("%s is logging out, on node %d", user->loginname, mynode);
disconnect(socket);
disconnect(socket, "Log out");
}

2
bbs.h
View File

@ -147,7 +147,7 @@ extern char s_getchar(int socket);
extern void s_readpass(int socket, char *buffer, int max);
extern void s_readstring(int socket, char *buffer, int max);
extern char s_getc(int socket);
extern void disconnect(int socket);
extern void disconnect(int socket, char *calledby);
extern void display_info(int socket);
extern void display_last10_callers(int socket, struct user_record *user);

View File

@ -172,7 +172,7 @@ void chat_system(int sock, struct user_record *user) {
len = read(sock, &c, 1);
if (len == 0) {
raw("QUIT\r\n");
disconnect(sock);
disconnect(sock, "Socket closed");
}
if (c == '\r') {

View File

@ -204,7 +204,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
len = read(socket, &c, 1);
if (len == 0) {
close(master);
disconnect(socket);
disconnect(socket, "Socket Closed");
return;
}
if (c == '\n' || c == '\0') {

View File

@ -128,7 +128,7 @@ int doIO(ZModem *zm) {
} else if (i > 0) {
len = read(zm->ifd, buffer, 2048);
if (len == 0) {
disconnect(zm->ifd);
disconnect(zm->ifd, "Socket closed");
}
pos = 0;

7
main.c
View File

@ -64,6 +64,13 @@ int main(int argc, char **argv) {
c = sizeof(struct sockaddr_in);
while ((client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) {
if (client_sock == -1) {
if (errno == EINTR) {
continue;
} else {
exit(-1);
}
}
pid = fork();
if (pid < 0) {