/** Handle events that may need handling. * This routine is polled from bsd.c. At any call, it can handle * the HUP and USR1 signals. At calls that are 'on the second', * it goes on to perform regular every-second processing and to * check whether it's time to do other periodic processes like * purge, dump, or inactivity checks. */ void dispatch(void) { static int idle_counter = 0; struct module_entry_t *m; void (*handle)(void); /* A HUP reloads configuration and reopens logs */ if (hup_triggered) { do_rawlog(LT_ERR, T("SIGHUP received: reloading .txt and .cnf files")); config_file_startup(NULL, 0); config_file_startup(NULL, 1); fcache_load(NOTHING); help_reindex(NOTHING); read_access_file(); reopen_logs(); hup_triggered = 0; } /* A USR1 does a shutdown/reboot */ if (usr1_triggered) { do_reboot(NOTHING, 0); /* We don't return from this */ usr1_triggered = 0; /* But just in case */ } if (!globals.on_second) return; globals.on_second = 0; mudtime = time(NULL); do_second(); migrate_stuff(CHUNK_MIGRATE_AMOUNT); if (options.purge_counter <= mudtime) { /* Free list reconstruction */ options.purge_counter = options.purge_interval + mudtime; global_eval_context.cplr = NOTHING; strcpy(global_eval_context.ccom, "purge"); purge(); strcpy(global_eval_context.ccom, ""); } if (options.dbck_counter <= mudtime) { /* Database consistency check */ options.dbck_counter = options.dbck_interval + mudtime; global_eval_context.cplr = NOTHING; strcpy(global_eval_context.ccom, "dbck"); dbck(); strcpy(global_eval_context.ccom, ""); } if (idle_counter <= mudtime) { /* Inactivity check */ idle_counter = 30 + mudtime; inactivity_check(); } /* Database dump routines */ if (options.dump_counter <= mudtime) { log_mem_check(); options.dump_counter = options.dump_interval + mudtime; global_eval_context.cplr = NOTHING; strcpy(global_eval_context.ccom, "dump"); fork_and_dump(1); strcpy(global_eval_context.ccom, ""); flag_broadcast(0, "ON-VACATION", "%s", T ("Your ON-VACATION flag is set! If you're back, clear it.")); } else if (NO_FORK && (options.dump_counter - 60 == mudtime) && *options.dump_warning_1min) { flag_broadcast(0, 0, "%s", options.dump_warning_1min); } else if (NO_FORK && (options.dump_counter - 300 == mudtime) && *options.dump_warning_5min) { flag_broadcast(0, 0, "%s", options.dump_warning_5min); } if (options.warn_interval && (options.warn_counter <= mudtime)) { options.warn_counter = options.warn_interval + mudtime; global_eval_context.cplr = NOTHING; strcpy(global_eval_context.ccom, "warnings"); run_topology(); strcpy(global_eval_context.ccom, ""); } #ifdef MUSHCRON if((mudtime % 60) == 0) run_cron(); /* Run the MUSH Cron Daemon */ #endif /* MUSHCRON */ #ifdef _SWMP_ sql_timer(); #endif #ifdef RPMODE_SYS rplog_reset(); #endif /* Replacement for local_timer */ MODULE_ITER(m) MODULE_FUNC_NOARGS(handle, m->handle, "module_timer"); }
void NDECL(dispatch) { char *cmdsave; cmdsave = mudstate.debug_cmd; mudstate.debug_cmd = (char *)"< dispatch >"; /* this routine can be used to poll from interface.c */ if (!mudstate.alarm_triggered) return; mudstate.alarm_triggered = 0; mudstate.lastnowmsec = mudstate.nowmsec; mudstate.lastnow = mudstate.now; mudstate.nowmsec = time_ng(NULL); mudstate.now = (time_t) floor(mudstate.nowmsec); do_second(); local_second(); /* Free list reconstruction */ if ((mudconf.control_flags & CF_DBCHECK) && (mudstate.check_counter <= mudstate.nowmsec)) { mudstate.check_counter = mudconf.check_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< dbck >"; cache_reset(0); do_dbck (NOTHING, NOTHING, 0); cache_reset(0); pcache_trim(); } /* Database dump routines */ if ((mudconf.control_flags & CF_CHECKPOINT) && (mudstate.dump_counter <= mudstate.nowmsec)) { mudstate.dump_counter = mudconf.dump_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< dump >"; fork_and_dump(0, (char *)NULL); } /* Idle user check */ if ((mudconf.control_flags & CF_IDLECHECK) && (mudstate.idle_counter <= mudstate.nowmsec)) { mudstate.idle_counter = mudconf.idle_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< idlecheck >"; cache_reset(0); check_idle(); } #ifdef HAVE_GETRUSAGE /* Memory use stats */ if (mudstate.mstats_counter <= mudstate.nowmsec) { int curr; mudstate.mstats_counter = 15 + mudstate.nowmsec; curr = mudstate.mstat_curr; if ( (curr >= 0 ) && (mudstate.now > mudstate.mstat_secs[curr]) ) { struct rusage usage; curr = 1-curr; getrusage(RUSAGE_SELF, &usage); mudstate.mstat_ixrss[curr] = usage.ru_ixrss; mudstate.mstat_idrss[curr] = usage.ru_idrss; mudstate.mstat_isrss[curr] = usage.ru_isrss; mudstate.mstat_secs[curr] = mudstate.now; mudstate.mstat_curr = curr; } } #endif #ifdef RWHO_IN_USE if ((mudconf.control_flags & CF_RWHO_XMIT) && (mudstate.rwho_counter <= mudstate.nowmsec)) { mudstate.rwho_counter = mudconf.rwho_interval + mudstate.nowmsec; mudstate.debug_cmd = (char *)"< rwho update >"; rwho_update(); } #endif /* reset alarm */ alarm_msec (next_timer()); mudstate.debug_cmd = cmdsave; }