]> code.citadel.org Git - citadel.git/blobdiff - webcit/context_loop.c
CONTEXT: add interlock with cleanup / attaching of sessions.
[citadel.git] / webcit / context_loop.c
index 785fdb6aa4996b504d3709c9df80b99a9f8fba10..6fab115fad22bd156cf7779246561840d184de2b 100644 (file)
@@ -58,6 +58,7 @@ void do_housekeeping(void)
 {
        wcsession *sptr, *ss;
        wcsession *sessions_to_kill = NULL;
+       time_t the_time;
 
        /*
         * Lock the session list, moving any candidates for euthanasia into
@@ -65,9 +66,12 @@ void do_housekeeping(void)
         */
        CtdlLogResult(pthread_mutex_lock(&SessionListMutex));
        for (sptr = SessionList; sptr != NULL; sptr = sptr->next) {
-
+               if (the_time == 0)
+                       the_time = time(NULL);
                /* Kill idle sessions */
-               if ((time(NULL) - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT) {
+               if ((sptr->inuse == 0) && 
+                   ((the_time - (sptr->lastreq)) > (time_t) WEBCIT_TIMEOUT))
+               {
                        syslog(3, "Timeout session %d", sptr->wc_session);
                        sptr->killthis = 1;
                }
@@ -335,11 +339,12 @@ int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
        }
        else {
                /* If this is a "flat" request for the root, display the configured landing page. */
-               Hdr->HR.DontNeedAuth = 1;
+               int return_value;
                StrBuf *NewLine = NewStrBuf();
+               Hdr->HR.DontNeedAuth = 1;
                StrBufAppendPrintf(NewLine, "GET /landing?go=%s HTTP/1.0", ChrPtr(Buf));
                syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
-               int return_value = ReadHttpSubject(Hdr, NewLine, Buf);
+               return_value = ReadHttpSubject(Hdr, NewLine, Buf);
                FreeStrBuf(&NewLine);
                return return_value;
        }
@@ -559,7 +564,7 @@ void context_loop(ParsedHttpHdrs *Hdr)
        /*
         * If there were no qualifying sessions, then create a new one.
         */
-       if (TheSession == NULL) {
+       if ((TheSession == NULL) || (TheSession->killthis != 0)) {
                TheSession = CreateSession(1, 0, &SessionList, Hdr, &SessionListMutex);
        }