2 * This file contains housekeeping tasks which periodically
22 #include "citserver.h"
24 #include "housekeeping.h"
25 #include "sysdep_decls.h"
29 * Terminate idle sessions. This function pounds through the session table
30 * comparing the current time to each session's time-of-last-command. If an
31 * idle session is found it is terminated, then the search restarts at the
32 * beginning because the pointer to our place in the list becomes invalid.
34 void terminate_idle_sessions(void) {
35 struct CitContext *ccptr;
42 lprintf(9, "Scanning for timed out sessions...\n");
43 begin_critical_section(S_SESSION_TABLE);
44 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
46 && (config.c_sleeping > 0)
47 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
48 session_to_kill = ccptr->cs_pid;
51 end_critical_section(S_SESSION_TABLE);
52 lprintf(9, "...done scanning.\n");
53 if (session_to_kill > 0) {
54 lprintf(3, "Session %d timed out. Terminating it...\n",
56 kill_session(session_to_kill);
57 lprintf(9, "...done terminating it.\n");
59 } while(session_to_kill > 0);
64 * Main housekeeping function. This gets run whenever a session terminates.
66 void do_housekeeping(void) {
68 lprintf(9, "--- begin housekeeping ---\n");
69 begin_critical_section(S_HOUSEKEEPING);
71 * Terminate idle sessions.
73 lprintf(7, "Calling terminate_idle_sessions()\n");
74 terminate_idle_sessions();
75 lprintf(9, "Done with terminate_idle_sessions()\n");
78 * If the server is scheduled to shut down the next time all
79 * users are logged out, now's the time to do it.
81 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
82 lprintf(3, "Scheduled shutdown initiating.\n");
85 end_critical_section(S_HOUSEKEEPING);
86 lprintf(9, "--- end housekeeping ---\n");
92 * Check (and fix) floor reference counts. This doesn't need to be done
93 * very often, since the counts should remain correct during normal operation.
94 * NOTE: this function pair should ONLY be called during startup. It is NOT
97 void check_ref_counts_backend(struct quickroom *qrbuf) {
100 getfloor(&flbuf, qrbuf->QRfloor);
102 flbuf.f_flags = flbuf.f_flags | QR_INUSE;
103 putfloor(&flbuf, qrbuf->QRfloor);
106 void check_ref_counts(void) {
110 for (a=0; a<MAXFLOORS; ++a) {
112 flbuf.f_ref_count = 0;
113 flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
117 ForEachRoom(check_ref_counts_backend);