2 * This file contains housekeeping tasks which periodically
17 #include "citserver.h"
19 #include "housekeeping.h"
20 #include "sysdep_decls.h"
24 * Terminate idle sessions. This function pounds through the session table
25 * comparing the current time to each session's time-of-last-command. If an
26 * idle session is found it is terminated, then the search restarts at the
27 * beginning because the pointer to our place in the list becomes invalid.
29 void terminate_idle_sessions(void) {
30 struct CitContext *ccptr;
34 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
36 && (config.c_sleeping > 0)
37 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
38 lprintf(3, "Session %d timed out\n", ccptr->cs_pid);
39 kill_session(ccptr->cs_pid);
47 * Main housekeeping function. This gets run whenever a session terminates.
49 void do_housekeeping(void) {
51 begin_critical_section(S_HOUSEKEEPING);
53 * Terminate idle sessions.
55 lprintf(7, "Calling terminate_idle_sessions()\n");
56 terminate_idle_sessions();
59 * If the server is scheduled to shut down the next time all
60 * users are logged out, now's the time to do it.
62 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
63 lprintf(3, "Scheduled shutdown initiating.\n");
66 end_critical_section(S_HOUSEKEEPING);
72 * Check (and fix) floor reference counts. This doesn't need to be done
73 * very often, since the counts should remain correct during normal operation.
75 void check_ref_counts(void) {
77 struct quickroom qrbuf;
81 for (a=0; a<MAXFLOORS; ++a) ref[a] = 0;
83 for (a=0; a<MAXROOMS; ++a) {
85 if (qrbuf.QRflags & QR_INUSE) {
86 ++ref[(int)qrbuf.QRfloor];
90 for (a=0; a<MAXFLOORS; ++a) {
92 flbuf.f_ref_count = ref[a];
93 if (ref[a] > 0) flbuf.f_flags = flbuf.f_flags | QR_INUSE ;