]> code.citadel.org Git - citadel.git/blobdiff - citadel/citserver.c
More session table stability nonsense
[citadel.git] / citadel / citserver.c
index 69a12725699a07c35b53caf15214e4234c3c1bd2..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;
@@ -541,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);
@@ -559,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);
+               }
        }
 
 
@@ -662,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.
@@ -695,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) {