4 * This file contains miscellaneous housekeeping tasks.
18 #include <sys/types.h>
20 #ifdef HAVE_SYS_SELECT_H
21 #include <sys/select.h>
26 #include "citserver.h"
28 #include "housekeeping.h"
29 #include "sysdep_decls.h"
34 int housepipe[2]; /* This is the queue for housekeeping tasks */
38 * Terminate idle sessions. This function pounds through the session table
39 * comparing the current time to each session's time-of-last-command. If an
40 * idle session is found it is terminated, then the search restarts at the
41 * beginning because the pointer to our place in the list becomes invalid.
43 void terminate_idle_sessions(void) {
44 struct CitContext *ccptr;
51 begin_critical_section(S_SESSION_TABLE);
52 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
54 && (config.c_sleeping > 0)
55 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
60 end_critical_section(S_SESSION_TABLE);
61 lprintf(9, "Terminated %d idle sessions\n", killed);
66 void check_sched_shutdown(void) {
67 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
68 lprintf(3, "Scheduled shutdown initiating.\n");
76 * Check (and fix) floor reference counts. This doesn't need to be done
77 * very often, since the counts should remain correct during normal operation.
78 * NOTE: this function pair should ONLY be called during startup. It is NOT
81 void check_ref_counts_backend(struct quickroom *qrbuf, void *data) {
84 getfloor(&flbuf, qrbuf->QRfloor);
86 flbuf.f_flags = flbuf.f_flags | QR_INUSE;
87 putfloor(&flbuf, qrbuf->QRfloor);
90 void check_ref_counts(void) {
94 lprintf(7, "Checking floor reference counts\n");
95 for (a=0; a<MAXFLOORS; ++a) {
97 flbuf.f_ref_count = 0;
98 flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
102 ForEachRoom(check_ref_counts_backend, NULL);