From 17daa21763656d90d71305016470db47de7f5cfe Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 30 Jan 2013 00:23:29 +0100 Subject: [PATCH] CONTEXT: add interlock with cleanup / attaching of sessions. --- webcit/context_loop.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webcit/context_loop.c b/webcit/context_loop.c index ff95e825e..6fab115fa 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -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; } @@ -560,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); } -- 2.30.2