From 4303912101a6e8f6dfb736704a72fa4591995799 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 26 Oct 1999 03:48:40 +0000 Subject: [PATCH] * Shuffled around the order of events when a thread is terminating. All mutex operations now happen prior to the freeing of the CitContext structure, otherwise begin_critical_section() and end_critical_section() try to manipulate the context's mutex count when there isn't any context. --- citadel/ChangeLog | 9 ++++++--- citadel/citserver.c | 12 ++---------- citadel/housekeeping.c | 7 ++----- citadel/sysdep.c | 13 +++++++++++-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 18a4babd3..7b0ce4ea9 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,10 +1,13 @@ $Log$ +Revision 1.395 1999/10/26 03:48:39 ajc +* Shuffled around the order of events when a thread is terminating. All + mutex operations now happen prior to the freeing of the CitContext structure, + otherwise begin_critical_section() and end_critical_section() try to + manipulate the context's mutex count when there isn't any context. + Revision 1.394 1999/10/26 03:21:16 ajc * Changed a lot of strncpy() calls to safestrncpy() and replaced most of their hardcoded size arguments with 'sizeof' based arguments. -* Moved the CitContext destruction into the housekeeper thread and out of the - thread being cancelled. Didn't fix it, though (to see what happens, link - the server against ElectricFence and watch what happens when a session ends). Revision 1.393 1999/10/24 19:22:51 nbryant * Makefile.in, configure.in: added --enable-icq flag; made checks for diff --git a/citadel/citserver.c b/citadel/citserver.c index 7343e230d..8a9f9b9ec 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -124,8 +124,6 @@ void deallocate_user_data(struct CitContext *con) */ void cleanup_stuff(void *arg) { - char buf[256]; - lprintf(9, "cleanup_stuff() called\n"); lprintf(7, "Calling logout(%d)\n", CC->cs_pid); @@ -148,14 +146,8 @@ void cleanup_stuff(void *arg) * halfway through, and the context being destroyed can't be the one * doing the work. */ - lprintf(7, "Scheduling housekeeper REMOVE_CONTEXT(%d)\n", CC->cs_pid); - sprintf(buf, "REMOVE_CONTEXT|%d", CC->cs_pid); - enter_housekeeping_cmd(buf); - - /* Tell the housekeeping thread to check to see if this is the time - * to initiate a scheduled shutdown event. - */ - enter_housekeeping_cmd("SCHED_SHUTDOWN"); + lprintf(7, "Calling RemoveContext(%d)\n", CC->cs_pid); + RemoveContext(CC->cs_pid); } diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index fef2f694c..726c92815 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -134,11 +134,6 @@ void housekeeping_loop(void) { check_sched_shutdown(); } - /* Remove a context (session ending) */ - else if (!strcmp(cmd, "REMOVE_CONTEXT")) { - RemoveContext( extract_int(house_cmd, 1) ); - } - /* Unknown */ else { lprintf(7, "Unknown housekeeping command\n"); @@ -156,10 +151,12 @@ void housekeeping_loop(void) { void enter_housekeeping_cmd(char *cmd) { char cmdbuf[256]; + lprintf(9, "enter_housekeeping_cmd(%s)\n", cmd); safestrncpy(cmdbuf, cmd, 256); begin_critical_section(S_HOUSEKEEPING); write(housepipe[1], cmdbuf, 256); end_critical_section(S_HOUSEKEEPING); + lprintf(9, "leaving enter_housekeeping_cmd()\n"); } diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 26d132b5f..32fb846e9 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -256,7 +256,7 @@ void begin_critical_section(int which_one) /* Keep a count of how many critical sections this thread has * open, so that end_critical_section() doesn't enable * cancellation prematurely. */ - CC->n_crit++; + if (CC != NULL) CC->n_crit++; #ifdef HAVE_PTHREAD_CANCEL /* Don't get interrupted during the critical section */ pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldval); @@ -291,6 +291,7 @@ void end_critical_section(int which_one) pthread_mutex_unlock(&Critters[which_one]); if (!pthread_equal(pthread_self(), main_thread_id)) + if (CC != NULL) if (!--CC->n_crit) { #ifdef HAVE_PTHREAD_CANCEL /* If a cancel was sent during the critical section, do it now. @@ -464,11 +465,19 @@ void RemoveContext(int con) } + end_critical_section(S_SESSION_TABLE); + lprintf(7, "Closing socket %d\n", ToFree->client_socket); close(ToFree->client_socket); + + /* Tell the housekeeping thread to check to see if this is the time + * to initiate a scheduled shutdown event. + */ + enter_housekeeping_cmd("SCHED_SHUTDOWN"); + + /* Free up the memory used by this context */ phree(ToFree); - end_critical_section(S_SESSION_TABLE); lprintf(7, "Done with RemoveContext\n"); } -- 2.30.2