]> code.citadel.org Git - citadel.git/commitdiff
* sysdep.c, citserver.c: (hopefully) fixed a session table concurrency
authorArt Cancro <ajc@citadel.org>
Sun, 13 Dec 1998 22:41:02 +0000 (22:41 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 13 Dec 1998 22:41:02 +0000 (22:41 +0000)
          bug which was causing the server to occasionally crash.

citadel/ChangeLog
citadel/citserver.c
citadel/sysdep.c

index da6067e7fa656d9b47c32638b23d55feb92b0753..26474ad373720b8302994fc2306f518941f0bcfd 100644 (file)
@@ -1,3 +1,7 @@
+Sun Dec 13 17:40:08 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+       * sysdep.c, citserver.c: (hopefully) fixed a session table concurrency
+         bug which was causing the server to occasionally crash.
+
 Fri Dec 11 18:50:00 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * setup.c: default value for maxsessions is now 0 (no limit)
        * room_ops.c: don't allow users to create a room called "Mail"
index 8a967629826e288d5196a5ed6a2cb105365ae6df..846fb071215974d4be07e55542b1c477a28df0a3 100644 (file)
@@ -542,6 +542,7 @@ void cmd_term(char *cmdbuf)
 {
        int session_num;
        struct CitContext *ccptr;
+       int session_to_kill = 0;
 
        if (!CC->logged_in) {
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
@@ -560,15 +561,21 @@ void cmd_term(char *cmdbuf)
                return;
                }
 
+       begin_critical_section(S_SESSION_TABLE);
        for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
                if (session_num == ccptr->cs_pid) {
-                       kill_session(ccptr->cs_pid);
-                       cprintf("%d Session terminated.\n", OK);
-                       return;
+                       session_to_kill = ccptr->cs_pid;
                        }
                }
+       end_critical_section(S_SESSION_TABLE);
 
-       cprintf("%d No such session.\n", ERROR);
+       if (session_to_kill > 0) {
+               kill_session(ccptr->cs_pid);
+               cprintf("%d Session terminated.\n", OK);
+               }
+       else {
+               cprintf("%d No such session.\n", ERROR);
+               }
        }
 
 
@@ -663,7 +670,7 @@ void cmd_scdn(char *argbuf)
 void *context_loop(struct CitContext *con)
 {
        char cmdbuf[256];
-       int session_num;
+       int num_sessions;
 
        /*
         * Wedge our way into the context table.
@@ -696,9 +703,9 @@ void *context_loop(struct CitContext *con)
        CC->upload_type = UPL_FILE;
        CC->dl_is_net = 0;
 
-       session_num = session_count();
+       num_sessions = session_count();
        CC->nologin = 0;
-       if ((config.c_maxsessions > 0)&&(session_num > config.c_maxsessions))
+       if ((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions))
                CC->nologin = 1;
 
        if (CC->nologin==1) {
index 05828026e045605e622d5d2848d0cf92168d1698..57fae4f48822dadb47853066be9aa16c9d12598f 100644 (file)
@@ -282,6 +282,10 @@ void RemoveContext(struct CitContext *con)
                return;
                }
 
+       /*
+        * session_count() starts its own S_SESSION_TABLE critical section;
+        * so do not call it from within this loop.
+        */
        begin_critical_section(S_SESSION_TABLE);
        lprintf(7, "Closing socket %d\n", con->client_socket);
        close(con->client_socket);
@@ -301,12 +305,12 @@ void RemoveContext(struct CitContext *con)
        lprintf(9, "Freeing session context...\n");     
        free(con);
        lprintf(9, "...done.\n");
+       end_critical_section(S_SESSION_TABLE);
 
        lprintf(9, "Session count after RemoveContext is %d\n",
                session_count());
 
        lprintf(7, "Done with RemoveContext\n");
-       end_critical_section(S_SESSION_TABLE);
        }
 
 
@@ -319,10 +323,12 @@ int session_count(void) {
        int TheCount = 0;
 
        lprintf(9, "session_count() starting\n");
+       begin_critical_section(S_SESSION_TABLE);
        for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
                ++TheCount;
                lprintf(9, "Counted session %3d (%d)\n", ptr->cs_pid, TheCount);
                }
+       end_critical_section(S_SESSION_TABLE);
 
        lprintf(9, "session_count() finishing\n");
        return(TheCount);