]> code.citadel.org Git - citadel.git/blobdiff - citadel/context.c
Backport infanticide prevention patch from head
[citadel.git] / citadel / context.c
index b00f6c07c98bffab2183807f825f72e701b03a08..2681d85a80b986ac868bcf7dbbbb989797413ddd 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: sysdep.c 7989 2009-10-31 15:29:37Z davew $
- *
  * Citadel context management stuff.
  * Here's where we (hopefully) have all the code that manipulates contexts.
  *
@@ -345,6 +343,7 @@ void RemoveContext (CitContext *con)
 
        FreeStrBuf(&con->MigrateBuf);
        FreeStrBuf(&con->ReadBuf);
+       FreeStrBuf(&con->lBuf);
        CtdlLogPrintf(CTDL_DEBUG, "Done with RemoveContext()\n");
 }
 
@@ -367,7 +366,7 @@ CitContext *CreateNewContext(void) {
                return NULL;
        }
        memset(me, 0, sizeof(CitContext));
-       
+       me->lBuf = NewStrBufPlain(NULL, SIZ);
        /* Give the contaxt a name. Hopefully makes it easier to track */
        strcpy (me->user.fullname, "SYS_notauth");
        
@@ -386,6 +385,7 @@ CitContext *CreateNewContext(void) {
        me->cs_pid = ++next_pid;
        me->prev = NULL;
        me->next = ContextList;
+       me->lastcmd = time(NULL);       /* set lastcmd to now to prevent idle timer infanticide */
        ContextList = me;
        if (me->next != NULL) {
                me->next->prev = me;
@@ -434,11 +434,14 @@ void CtdlFillSystemContext(CitContext *context, char *name)
        long len;
 
        memset(context, 0, sizeof(CitContext));
+       context->lBuf = NewStrBuf();
        context->internal_pgm = 1;
        context->cs_pid = 0;
        strcpy (sysname, "SYS_");
        strcat (sysname, name);
        len = cutuserkey(sysname);
+       memcpy(context->curr_user, sysname, len + 1);
+
        /* internal_create_user has the side effect of loading the user regardless of wether they
         * already existed or needed to be created
         */
@@ -455,6 +458,18 @@ void CtdlFillSystemContext(CitContext *context, char *name)
        }
 }
 
+/*
+ * flush it again...
+ */
+void CtdlClearSystemContext(void)
+{
+       CitContext *CCC = CC;
+
+       FreeStrBuf(&CCC->lBuf);
+       memset(CCC, 0, sizeof(CitContext));
+       citthread_setspecific(MyConKey, NULL);
+}
+
 /*
  * Cleanup any contexts that are left lying around
  */
@@ -578,27 +593,12 @@ void InitializeMasterCC(void) {
        memset(&masterCC, 0, sizeof( CitContext));
        masterCC.internal_pgm = 1;
        masterCC.cs_pid = 0;
+       masterCC.lBuf = NewStrBuf ();
 }
 
 
 
 
-/*
- * Bind a thread to a context.  (It's inline merely to speed things up.)
- */
-INLINE void become_session(CitContext *which_con) {
-/*
-       pid_t tid = syscall(SYS_gettid);
-*/
-       citthread_setspecific(MyConKey, (void *)which_con );
-/*
-       CtdlLogPrintf(CTDL_DEBUG, "[%d]: Now doing %s\n", 
-                     (int) tid, 
-                     ((which_con != NULL) && (which_con->ServiceName != NULL)) ? 
-                     which_con->ServiceName:"");
-*/
-}
-
 
 /*
  * Set the "async waiting" flag for a session, if applicable