* Master listening sockets are now non blocking, in order to deal with
authorArt Cancro <ajc@citadel.org>
Mon, 21 Feb 2005 21:38:21 +0000 (21:38 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 21 Feb 2005 21:38:21 +0000 (21:38 +0000)
  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.

citadel/room_ops.c
citadel/serv_chat.c
citadel/serv_imap.c
citadel/sysdep.c

index 7a1eed03fb28ef6fedad2e86fc82ef23611effd9..a03b349b525308b9c31f4dd33013a740421770e9 100644 (file)
@@ -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;
index f03e4e00b630972260e04b97935b94c39ffa613b..e8d1e46eee6fb9ebfa978033db636c973db106ec 100644 (file)
@@ -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;
 
index 01d7b50f9c1bc133435e3cba1bc4aea9523b4a69..bc3193be1b0457302a716b5cb7e7f518ba368a8b 100644 (file)
@@ -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",
index e8894a2fc86b6a52bf59153c5048f3d567e16219..db6405a1fce4335361359b8737d29d8cfafc64a3 100644 (file)
@@ -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