From: Art Cancro Date: Mon, 21 Feb 2005 21:38:21 +0000 (+0000) Subject: * Master listening sockets are now non blocking, in order to deal with X-Git-Tag: v7.86~5027 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=a6f716541785fc43dde40f38ff76261a48517808;p=citadel.git * Master listening sockets are now non blocking, in order to deal with rare situations where select() lights up a master socket but there are no incoming connections. Making the socket non blocking keeps the accept() call from blocking, which would subsequently lock the whole server until a new connection arrives. --- diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 7a1eed03f..a03b349b5 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -1617,13 +1617,14 @@ unsigned create_room(char *new_room_name, struct floor flbuf; struct visit vbuf; - lprintf(CTDL_DEBUG, "create_room(%s)\n", new_room_name); + lprintf(CTDL_DEBUG, "create_room(name=%s, type=%d, view=%d)\n", + new_room_name, new_room_type, new_room_view); + if (getroom(&qrbuf, new_room_name) == 0) { lprintf(CTDL_DEBUG, "%s already exists.\n", new_room_name); - return (0); /* already exists */ + return(0); } - memset(&qrbuf, 0, sizeof(struct ctdlroom)); safestrncpy(qrbuf.QRpasswd, new_room_pass, sizeof qrbuf.QRpasswd); qrbuf.QRflags = QR_INUSE; diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index f03e4e00b..e8d1e46ee 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -241,8 +241,6 @@ void cmd_chat(char *argbuf) struct CitContext *t_context; int retval; - unbuffer_output(); - if (!(CC->logged_in)) { cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN); return; @@ -251,6 +249,7 @@ void cmd_chat(char *argbuf) CC->cs_flags = CC->cs_flags | CS_CHAT; cprintf("%d Entering chat mode (type '/help' for available commands)\n", START_CHAT_MODE); + unbuffer_output(); MyLastMsg = ChatLastMsg; diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 01d7b50f9..bc3193be1 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -828,7 +828,8 @@ void imap_create(int num_parms, char *parms[]) char roomname[ROOMNAMELEN]; int floornum; int flags; - int newroomtype; + int newroomtype = 0; + int newroomview = 0; if (strchr(parms[2], '\\') != NULL) { cprintf("%s NO Invalid character in folder name\r\n", @@ -856,15 +857,17 @@ void imap_create(int num_parms, char *parms[]) } if (flags & IR_MAILBOX) { - newroomtype = 4; /* private mailbox */ + newroomtype = 4; /* private mailbox */ + newroomview = VIEW_MAILBOX; } else { - newroomtype = 0; /* public folder */ + newroomtype = 0; /* public folder */ + newroomview = VIEW_BBS; } lprintf(CTDL_INFO, "Create new room <%s> on floor <%d> with type <%d>\n", roomname, floornum, newroomtype); - ret = create_room(roomname, newroomtype, "", floornum, 1, 0, VIEW_BBS); + ret = create_room(roomname, newroomtype, "", floornum, 1, 0, newroomview); if (ret == 0) { cprintf ("%s NO Mailbox already exists, or create failed\r\n", diff --git a/citadel/sysdep.c b/citadel/sysdep.c index e8894a2fc..db6405a1f 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -212,12 +212,16 @@ void init_sysdep(void) { sigaddset(&set, SIGHUP); sigaddset(&set, SIGTERM); sigaddset(&set, SIGSEGV); + sigaddset(&set, SIGILL); + sigaddset(&set, SIGBUS); sigprocmask(SIG_UNBLOCK, &set, NULL); signal(SIGINT, signal_cleanup); signal(SIGQUIT, signal_cleanup); signal(SIGHUP, signal_cleanup); signal(SIGTERM, signal_cleanup); signal(SIGSEGV, signal_cleanup); + signal(SIGILL, signal_cleanup); + signal(SIGBUS, signal_cleanup); /* * Do not shut down the server on broken pipe signals, otherwise the @@ -305,6 +309,14 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len) return(-1); } + /* set to nonblock - we need this for some obscure situations */ + if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { + lprintf(CTDL_EMERG, "citserver: Can't set socket to non-blocking: %s\n", + strerror(errno)); + close(s); + return(-1); + } + if (listen(s, actual_queue_len) < 0) { lprintf(CTDL_EMERG, "citserver: Can't listen: %s\n", strerror(errno)); close(s); @@ -353,6 +365,14 @@ int ig_uds_server(char *sockpath, int queue_len) return(-1); } + /* set to nonblock - we need this for some obscure situations */ + if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { + lprintf(CTDL_EMERG, "citserver: Can't set socket to non-blocking: %s\n", + strerror(errno)); + close(s); + return(-1); + } + if (listen(s, actual_queue_len) < 0) { lprintf(CTDL_EMERG, "citserver: Can't listen: %s\n", strerror(errno)); return(-1); @@ -959,7 +979,9 @@ do_select: force_purge = 0; } end_critical_section(S_SESSION_TABLE); - if (bind_me) goto SKIP_SELECT; + if (bind_me) { + goto SKIP_SELECT; + } /* If we got this far, it means that there are no sessions * which a previous thread marked for attention, so we go