2 * This file contains housekeeping tasks which periodically
19 #include "citserver.h"
21 #include "housekeeping.h"
22 #include "sysdep_decls.h"
26 * Terminate idle sessions. This function pounds through the session table
27 * comparing the current time to each session's time-of-last-command. If an
28 * idle session is found it is terminated, then the search restarts at the
29 * beginning because the pointer to our place in the list becomes invalid.
31 void terminate_idle_sessions(void) {
32 struct CitContext *ccptr;
36 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
38 && (config.c_sleeping > 0)
39 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
40 lprintf(3, "Session %d timed out\n", ccptr->cs_pid);
41 kill_session(ccptr->cs_pid);
49 * Main housekeeping function. This gets run whenever a session terminates.
51 void do_housekeeping(void) {
53 begin_critical_section(S_HOUSEKEEPING);
55 * Terminate idle sessions.
57 lprintf(7, "Calling terminate_idle_sessions()\n");
58 terminate_idle_sessions();
61 * If the server is scheduled to shut down the next time all
62 * users are logged out, now's the time to do it.
64 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
65 lprintf(3, "Scheduled shutdown initiating.\n");
68 end_critical_section(S_HOUSEKEEPING);
74 * Check (and fix) floor reference counts. This doesn't need to be done
75 * very often, since the counts should remain correct during normal operation.
76 * NOTE: this function pair should ONLY be called during startup. It is NOT
79 void check_ref_counts_backend(struct quickroom *qrbuf) {
82 lgetfloor(&flbuf, qrbuf->QRfloor);
84 flbuf.f_flags = flbuf.f_flags | QR_INUSE;
85 lputfloor(&flbuf, qrbuf->QRfloor);
88 void check_ref_counts(void) {
92 for (a=0; a<MAXFLOORS; ++a) {
94 flbuf.f_ref_count = 0;
95 flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
99 ForEachRoom(check_ref_counts_backend);