2 * This file contains housekeeping tasks which periodically
18 #include "citserver.h"
21 * Terminate idle sessions. This function pounds through the session table
22 * comparing the current time to each session's time-of-last-command. If an
23 * idle session is found it is terminated, then the search restarts at the
24 * beginning because the pointer to our place in the list becomes invalid.
26 void terminate_idle_sessions(void) {
27 struct CitContext *ccptr;
31 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
33 && (config.c_sleeping > 0)
34 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
35 lprintf(3, "Session %d timed out\n", ccptr->cs_pid);
36 kill_session(ccptr->cs_pid);
44 * Main housekeeping function. This gets run whenever a session terminates.
46 void do_housekeeping(void) {
48 begin_critical_section(S_HOUSEKEEPING);
50 * Terminate idle sessions.
52 lprintf(7, "Calling terminate_idle_sessions()\n");
53 terminate_idle_sessions();
56 * If the server is scheduled to shut down the next time all
57 * users are logged out, now's the time to do it.
59 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
60 lprintf(3, "Scheduled shutdown initiating.\n");
63 end_critical_section(S_HOUSEKEEPING);
69 * Check (and fix) floor reference counts. This doesn't need to be done
70 * very often, since the counts should remain correct during normal operation.
72 void check_ref_counts(void) {
74 struct quickroom qrbuf;
78 for (a=0; a<MAXFLOORS; ++a) ref[a] = 0;
80 for (a=0; a<MAXROOMS; ++a) {
82 if (qrbuf.QRflags & QR_INUSE) {
83 ++ref[(int)qrbuf.QRfloor];
87 for (a=0; a<MAXFLOORS; ++a) {
89 flbuf.f_ref_count = ref[a];
90 if (ref[a] > 0) flbuf.f_flags = flbuf.f_flags | QR_INUSE ;