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;
39 lprintf(9, "Scanning for timed out sessions...\n");
40 begin_critical_section(S_SESSION_TABLE);
41 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
43 && (config.c_sleeping > 0)
44 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
45 session_to_kill = ccptr->cs_pid;
48 end_critical_section(S_SESSION_TABLE);
49 lprintf(9, "...done scanning.\n");
50 if (session_to_kill > 0) {
51 lprintf(3, "Session %d timed out. Terminating it...\n",
53 kill_session(ccptr->cs_pid);
54 lprintf(9, "...done terminating it.\n");
56 } while(session_to_kill > 0);
61 * Main housekeeping function. This gets run whenever a session terminates.
63 void do_housekeeping(void) {
65 lprintf(9, "--- begin housekeeping ---\n");
66 begin_critical_section(S_HOUSEKEEPING);
68 * Terminate idle sessions.
70 lprintf(7, "Calling terminate_idle_sessions()\n");
71 terminate_idle_sessions();
72 lprintf(9, "Done with terminate_idle_sessions()\n");
75 * If the server is scheduled to shut down the next time all
76 * users are logged out, now's the time to do it.
78 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
79 lprintf(3, "Scheduled shutdown initiating.\n");
82 end_critical_section(S_HOUSEKEEPING);
83 lprintf(9, "--- end housekeeping ---\n");
89 * Check (and fix) floor reference counts. This doesn't need to be done
90 * very often, since the counts should remain correct during normal operation.
91 * NOTE: this function pair should ONLY be called during startup. It is NOT
94 void check_ref_counts_backend(struct quickroom *qrbuf) {
97 lgetfloor(&flbuf, qrbuf->QRfloor);
99 flbuf.f_flags = flbuf.f_flags | QR_INUSE;
100 lputfloor(&flbuf, qrbuf->QRfloor);
103 void check_ref_counts(void) {
107 for (a=0; a<MAXFLOORS; ++a) {
108 lgetfloor(&flbuf, a);
109 flbuf.f_ref_count = 0;
110 flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
111 lputfloor(&flbuf, a);
114 ForEachRoom(check_ref_counts_backend);