Added reason for disconnect, fixed minix EINTR during accept
This commit is contained in:
parent
c7046a66f3
commit
b48c0df31a
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ last10.dat
|
|||||||
ansis/*
|
ansis/*
|
||||||
config/*
|
config/*
|
||||||
illusion/*
|
illusion/*
|
||||||
|
scripts/*
|
||||||
logs/*
|
logs/*
|
||||||
*.a
|
*.a
|
||||||
lua/lua
|
lua/lua
|
||||||
|
28
bbs.c
28
bbs.c
@ -119,7 +119,7 @@ void timer_handler(int signum) {
|
|||||||
|
|
||||||
if (gUser->timeleft <= 0) {
|
if (gUser->timeleft <= 0) {
|
||||||
s_putstring(gSocket, "\r\n\r\nSorry, you're out of time today..\r\n");
|
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) {
|
if (usertimeout <= 0) {
|
||||||
s_putstring(gSocket, "\r\n\r\nTimeout waiting for input..\r\n");
|
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);
|
len = read(socket, &c, 1);
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(socket);
|
disconnect(socket, "Socket Closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
while (c == 255) {
|
while (c == 255) {
|
||||||
len = read(socket, &c, 1);
|
len = read(socket, &c, 1);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(socket);
|
disconnect(socket, "Socket Closed");
|
||||||
} else if (c == 255) {
|
} else if (c == 255) {
|
||||||
usertimeout = 10;
|
usertimeout = 10;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
len = read(socket, &c, 1);
|
len = read(socket, &c, 1);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(socket);
|
disconnect(socket, "Socket Closed");
|
||||||
}
|
}
|
||||||
len = read(socket, &c, 1);
|
len = read(socket, &c, 1);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(socket);
|
disconnect(socket, "Socket Closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,7 +489,7 @@ char s_getchar(int socket) {
|
|||||||
|
|
||||||
if (c == '\r') {
|
if (c == '\r') {
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(socket);
|
disconnect(socket, "Socket Closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (c == '\n');
|
} 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];
|
char buffer[256];
|
||||||
if (gUser != NULL) {
|
if (gUser != NULL) {
|
||||||
save_user(gUser);
|
save_user(gUser);
|
||||||
}
|
}
|
||||||
dolog("Node %d disconnected", mynode);
|
dolog("Node %d disconnected (%s)", mynode, calledby);
|
||||||
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
|
||||||
remove(buffer);
|
remove(buffer);
|
||||||
close(socket);
|
close(socket);
|
||||||
@ -842,8 +842,6 @@ void runbbs(int socket, char *config_path, char *ip) {
|
|||||||
|
|
||||||
s_displayansi(socket, "issue");
|
s_displayansi(socket, "issue");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
s_putstring(socket, "\e[0mEnter your Login Name or NEW to create an account\r\n");
|
s_putstring(socket, "\e[0mEnter your Login Name or NEW to create an account\r\n");
|
||||||
s_putstring(socket, "Login:> ");
|
s_putstring(socket, "Login:> ");
|
||||||
|
|
||||||
@ -857,7 +855,7 @@ void runbbs(int socket, char *config_path, char *ip) {
|
|||||||
user = check_user_pass(socket, buffer, password);
|
user = check_user_pass(socket, buffer, password);
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
s_putstring(socket, "\r\nIncorrect Login.\r\n");
|
s_putstring(socket, "\r\nIncorrect Login.\r\n");
|
||||||
disconnect(socket);
|
disconnect(socket, "Incorrect Login");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=1;i<=conf.nodes;i++) {
|
for (i=1;i<=conf.nodes;i++) {
|
||||||
@ -866,14 +864,14 @@ void runbbs(int socket, char *config_path, char *ip) {
|
|||||||
nodefile = fopen(buffer, "r");
|
nodefile = fopen(buffer, "r");
|
||||||
if (!nodefile) {
|
if (!nodefile) {
|
||||||
printf("Error opening nodefile!\n");
|
printf("Error opening nodefile!\n");
|
||||||
disconnect(socket);
|
disconnect(socket, "Error opening nodefile!");
|
||||||
}
|
}
|
||||||
fgets(buffer, 256, nodefile);
|
fgets(buffer, 256, nodefile);
|
||||||
|
|
||||||
if (strcasecmp(user->loginname, buffer) == 0) {
|
if (strcasecmp(user->loginname, buffer) == 0) {
|
||||||
fclose(nodefile);
|
fclose(nodefile);
|
||||||
s_putstring(socket, "\r\nYou are already logged in.\r\n");
|
s_putstring(socket, "\r\nYou are already logged in.\r\n");
|
||||||
disconnect(socket);
|
disconnect(socket, "Already Logged in");
|
||||||
}
|
}
|
||||||
fclose(nodefile);
|
fclose(nodefile);
|
||||||
}
|
}
|
||||||
@ -966,5 +964,5 @@ void runbbs(int socket, char *config_path, char *ip) {
|
|||||||
|
|
||||||
s_displayansi(socket, "goodbye");
|
s_displayansi(socket, "goodbye");
|
||||||
dolog("%s is logging out, on node %d", user->loginname, mynode);
|
dolog("%s is logging out, on node %d", user->loginname, mynode);
|
||||||
disconnect(socket);
|
disconnect(socket, "Log out");
|
||||||
}
|
}
|
||||||
|
2
bbs.h
2
bbs.h
@ -147,7 +147,7 @@ extern char s_getchar(int socket);
|
|||||||
extern void s_readpass(int socket, char *buffer, int max);
|
extern void s_readpass(int socket, char *buffer, int max);
|
||||||
extern void s_readstring(int socket, char *buffer, int max);
|
extern void s_readstring(int socket, char *buffer, int max);
|
||||||
extern char s_getc(int socket);
|
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_info(int socket);
|
||||||
extern void display_last10_callers(int socket, struct user_record *user);
|
extern void display_last10_callers(int socket, struct user_record *user);
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ void chat_system(int sock, struct user_record *user) {
|
|||||||
len = read(sock, &c, 1);
|
len = read(sock, &c, 1);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
raw("QUIT\r\n");
|
raw("QUIT\r\n");
|
||||||
disconnect(sock);
|
disconnect(sock, "Socket closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == '\r') {
|
if (c == '\r') {
|
||||||
|
2
doors.c
2
doors.c
@ -204,7 +204,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
|
|||||||
len = read(socket, &c, 1);
|
len = read(socket, &c, 1);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
close(master);
|
close(master);
|
||||||
disconnect(socket);
|
disconnect(socket, "Socket Closed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (c == '\n' || c == '\0') {
|
if (c == '\n' || c == '\0') {
|
||||||
|
2
files.c
2
files.c
@ -128,7 +128,7 @@ int doIO(ZModem *zm) {
|
|||||||
} else if (i > 0) {
|
} else if (i > 0) {
|
||||||
len = read(zm->ifd, buffer, 2048);
|
len = read(zm->ifd, buffer, 2048);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(zm->ifd);
|
disconnect(zm->ifd, "Socket closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
7
main.c
7
main.c
@ -64,6 +64,13 @@ int main(int argc, char **argv) {
|
|||||||
c = sizeof(struct sockaddr_in);
|
c = sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
while ((client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) {
|
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();
|
pid = fork();
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
Reference in New Issue
Block a user