2 * This file contains housekeeping tasks which periodically
20 * Terminate idle sessions. This function pounds through the session table
21 * comparing the current time to each session's time-of-last-command. If an
22 * idle session is found it is terminated, then the search restarts at the
23 * beginning because the pointer to our place in the list becomes invalid.
25 void terminate_idle_sessions(void) {
26 struct CitContext *ccptr;
30 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
32 && (config.c_sleeping > 0)
33 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
34 lprintf(3, "Session %d timed out\n", ccptr->cs_pid);
35 kill_session(ccptr->cs_pid);
43 * Main housekeeping function. This gets run whenever a session terminates.
45 void do_housekeeping() {
47 begin_critical_section(S_HOUSEKEEPING);
49 * Terminate idle sessions.
51 lprintf(7, "Calling terminate_idle_sessions()\n");
52 terminate_idle_sessions();
55 * If the server is scheduled to shut down the next time all
56 * users are logged out, now's the time to do it.
58 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
59 lprintf(3, "Scheduled shutdown initiating.\n");
62 end_critical_section(S_HOUSEKEEPING);
68 * Check (and fix) floor reference counts. This doesn't need to be done
69 * very often, since the counts should remain correct during normal operation.
71 void check_ref_counts() {
73 struct quickroom qrbuf;
77 for (a=0; a<MAXFLOORS; ++a) ref[a] = 0;
79 for (a=0; a<MAXROOMS; ++a) {
81 if (qrbuf.QRflags & QR_INUSE) {
82 ++ref[(int)qrbuf.QRfloor];
86 for (a=0; a<MAXFLOORS; ++a) {
88 flbuf.f_ref_count = ref[a];
89 if (ref[a] > 0) flbuf.f_flags = flbuf.f_flags | QR_INUSE ;