4 * This file contains miscellaneous housekeeping tasks.
14 #if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
19 # include <sys/time.h>
29 #include <sys/types.h>
30 #ifdef HAVE_SYS_SELECT_H
31 #include <sys/select.h>
36 #include "citserver.h"
38 #include "housekeeping.h"
39 #include "sysdep_decls.h"
44 int housepipe[2]; /* This is the queue for housekeeping tasks */
48 * Terminate idle sessions. This function pounds through the session table
49 * comparing the current time to each session's time-of-last-command. If an
50 * idle session is found it is terminated, then the search restarts at the
51 * beginning because the pointer to our place in the list becomes invalid.
53 void terminate_idle_sessions(void) {
54 struct CitContext *ccptr;
61 begin_critical_section(S_SESSION_TABLE);
62 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
64 && (config.c_sleeping > 0)
65 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
70 end_critical_section(S_SESSION_TABLE);
71 lprintf(9, "Terminated %d idle sessions\n", killed);
76 void check_sched_shutdown(void) {
77 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
78 lprintf(3, "Scheduled shutdown initiating.\n");
86 * Check (and fix) floor reference counts. This doesn't need to be done
87 * very often, since the counts should remain correct during normal operation.
88 * NOTE: this function pair should ONLY be called during startup. It is NOT
91 void check_ref_counts_backend(struct quickroom *qrbuf, void *data) {
94 getfloor(&flbuf, qrbuf->QRfloor);
96 flbuf.f_flags = flbuf.f_flags | QR_INUSE;
97 putfloor(&flbuf, qrbuf->QRfloor);
100 void check_ref_counts(void) {
104 lprintf(7, "Checking floor reference counts\n");
105 for (a=0; a<MAXFLOORS; ++a) {
107 flbuf.f_ref_count = 0;
108 flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
112 ForEachRoom(check_ref_counts_backend, NULL);