From f175de70e711a13800fd805b087478da5c60de1a Mon Sep 17 00:00:00 2001 From: Dave West Date: Sun, 10 Jan 2010 12:41:01 +0000 Subject: [PATCH] Fix race condition that caused segfaults in imap and xmpp as seen on uncensored. The race was that a new connection could begin doing its greeting function and another thread could begin the connections command loop function before the greeting had completed setting up the connection environment. --- citadel/context.h | 3 ++- citadel/sysdep.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/citadel/context.h b/citadel/context.h index 24cfc6861..b8e48c42a 100644 --- a/citadel/context.h +++ b/citadel/context.h @@ -126,7 +126,8 @@ typedef struct CitContext CitContext; */ enum { CON_IDLE, /* This context is doing nothing */ - CON_STARTING, /* This context needs the greeting outputting */ + CON_GREETING, /* This context needs to output its greeting */ + CON_STARTING, /* This context is outputting its greeting */ CON_READY, /* This context needs attention */ CON_EXECUTING /* This context is bound to a thread */ }; diff --git a/citadel/sysdep.c b/citadel/sysdep.c index dfe3278f1..3d2db7da8 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -935,8 +935,9 @@ do_select: force_purge = 0; ptr->state = CON_EXECUTING; break; } - if ((bind_me == NULL) && (ptr->state == CON_STARTING)) { + if ((bind_me == NULL) && (ptr->state == CON_GREETING)) { bind_me = ptr; + ptr->state = CON_STARTING; break; } } @@ -1153,7 +1154,7 @@ void *select_on_master (void *arg) SO_REUSEADDR, &i, sizeof(i)); - con->state = CON_STARTING; + con->state = CON_GREETING; retval--; if (retval == 0) -- 2.30.2