]> code.citadel.org Git - citadel.git/blobdiff - citadel/citserver.c
More session table stability nonsense
[citadel.git] / citadel / citserver.c
index 885c8a15acec1b9bdb71c3c2b3c01f27d659c2dc..15c6d0c6c1239c439e51b32146844a796d317796 100644 (file)
@@ -29,6 +29,7 @@
 #include "dynloader.h"
 #include "policy.h"
 #include "control.h"
+#include "tools.h"
 
 struct CitContext *ContextList = NULL;
 int ScheduledShutdown = 0;
@@ -117,9 +118,6 @@ void cleanup_stuff(void *arg)
        /* Deallocate any message list we might have in memory */
        if (CC->msglist != NULL) free(CC->msglist);
 
-       /* Purge any stale user/room relationships */
-       PurgeStaleRelationships();
-
        /* Now get rid of the session and context */
        lprintf(7, "cleanup_stuff() calling RemoveContext(%d)\n", CC->cs_pid);
        RemoveContext(CC);
@@ -544,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);
@@ -562,15 +561,23 @@ void cmd_term(char *cmdbuf)
                return;
                }
 
+       lprintf(9, "Locating session to kill\n");
+       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);
+       lprintf(9, "session_to_kill == %d\n", session_to_kill);
 
-       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);
+               }
        }
 
 
@@ -665,7 +672,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.
@@ -698,9 +705,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) {