$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
*/
void cleanup_stuff(void *arg)
{
- char buf[256];
-
lprintf(9, "cleanup_stuff() called\n");
lprintf(7, "Calling logout(%d)\n", CC->cs_pid);
* 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);
}
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");
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");
}
/* 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);
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.
}
+ 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");
}