/*
* Cleanup routine to be called when the server is shutting down.
- * WARNING: It's no longer safe to call this function to force a shutdown.
- * Instead, set time_to_die = 1.
*/
-void master_cleanup(void) {
+void master_cleanup(int exitcode) {
struct CleanupFunctionHook *fcn;
+ static int already_cleaning_up = 0;
+
+ if (already_cleaning_up) while(1) sleep(1);
+ already_cleaning_up = 1;
/* Run any cleanup routines registered by loadable modules */
for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) {
#endif
/* Now go away. */
- lprintf(CTDL_NOTICE, "citserver: exiting.\n");
+ lprintf(CTDL_NOTICE, "citserver: Exiting with status %d.\n", exitcode);
fflush(stdout); fflush(stderr);
- exit(0);
+ exit(exitcode);
}
*/
void RemoveContext (struct CitContext *con)
{
- struct CitContext *ptr = NULL;
- struct CitContext *ToFree = NULL;
-
if (con==NULL) {
lprintf(CTDL_ERR, "WARNING: RemoveContext() called with NULL!\n");
return;
*/
lprintf(CTDL_DEBUG, "Removing context for session %d\n", con->cs_pid);
begin_critical_section(S_SESSION_TABLE);
- if (ContextList == con) {
- ToFree = ContextList;
- ContextList = ContextList->next;
- --num_sessions;
- }
- else {
- for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
- if (ptr->next == con) {
- /* See fair scheduling in sysdep.c */
- if (next_session == ptr->next)
- next_session = ptr->next->next;
- ToFree = ptr->next;
- ptr->next = ptr->next->next;
- --num_sessions;
- }
- }
- }
+ if (con->prev) con->prev->next = con->next; else ContextList = con->next;
+ if (con->next) con->next->prev = con->prev;
+ --num_sessions;
end_critical_section(S_SESSION_TABLE);
- if (ToFree == NULL) {
- lprintf(CTDL_DEBUG, "RemoveContext() found nothing to remove\n");
- return;
- }
-
/* Run any cleanup routines registered by loadable modules.
* Note 1: This must occur *before* deallocate_user_data() because the
* cleanup functions might touch dynamic session data.