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