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;
37 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
39 && (config.c_sleeping > 0)
40 && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
41 lprintf(3, "Session %d timed out. Terminating it...\n",
43 kill_session(ccptr->cs_pid);
44 lprintf(9, "...done terminating it.\n");
52 * Main housekeeping function. This gets run whenever a session terminates.
54 void do_housekeeping(void) {
56 lprintf(9, "--- begin housekeeping ---\n");
57 begin_critical_section(S_HOUSEKEEPING);
59 * Terminate idle sessions.
61 lprintf(7, "Calling terminate_idle_sessions()\n");
62 terminate_idle_sessions();
63 lprintf(9, "Done with terminate_idle_sessions()\n");
66 * If the server is scheduled to shut down the next time all
67 * users are logged out, now's the time to do it.
69 if ((ScheduledShutdown == 1) && (ContextList == NULL)) {
70 lprintf(3, "Scheduled shutdown initiating.\n");
73 end_critical_section(S_HOUSEKEEPING);
74 lprintf(9, "--- end housekeeping ---\n");
80 * Check (and fix) floor reference counts. This doesn't need to be done
81 * very often, since the counts should remain correct during normal operation.
82 * NOTE: this function pair should ONLY be called during startup. It is NOT
85 void check_ref_counts_backend(struct quickroom *qrbuf) {
88 lgetfloor(&flbuf, qrbuf->QRfloor);
90 flbuf.f_flags = flbuf.f_flags | QR_INUSE;
91 lputfloor(&flbuf, qrbuf->QRfloor);
94 void check_ref_counts(void) {
98 for (a=0; a<MAXFLOORS; ++a) {
100 flbuf.f_ref_count = 0;
101 flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
102 lputfloor(&flbuf, a);
105 ForEachRoom(check_ref_counts_backend);