From: Ari Johnson Date: Tue, 20 Feb 2007 20:35:49 +0000 (+0000) Subject: Moved several global variables to GLOBALTAB, as per PennMUSH X-Git-Tag: 0.73~173 X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=911d137c2b29949c7b62bca601498c6b672483ca;p=cobramush.git Moved several global variables to GLOBALTAB, as per PennMUSH --- diff --git a/hdrs/conf.h b/hdrs/conf.h index cdca180..65361d9 100644 --- a/hdrs/conf.h +++ b/hdrs/conf.h @@ -471,4 +471,22 @@ int cf_time(const char *opt, const char *val, void *loc, int maxval, #define GST_NUMBERING (options.guest_roman_numeral) #define GUEST_NUMBER(x) (const char *) (GST_NUMBERING ? ArabicToRoman(x) : unparse_number((NVAL) x)) #define PLAYER_DEF_POWERGROUP (options.player_powergroup) + +typedef struct globals_table GLOBALTAB; + +struct globals_table { + int database_loaded; /**< True after the database has been read. */ + char dumpfile[200]; /**< File name to dump database to */ + time_t start_time; /**< MUSH start time (since process exec'd) */ + time_t first_start_time; /**< MUSH start time (since last shutdown) */ + time_t last_dump_time; /**< Time of last successful db save */ + int reboot_count; /**< Number of reboots so far */ + int paranoid_dump; /**< if paranoid, scan before dumping */ + int paranoid_checkpt; /**< write out an okay message every x objs */ + long indb_flags; /**< flags set in the input database */ + int on_second; /**< is it time for per-second processes? */ +}; + +extern GLOBALTAB globals; + #endif /* __CONF_H */ diff --git a/src/bsd.c b/src/bsd.c index 8034147..08d5b56 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -153,17 +153,11 @@ void rusage_stats(void); #endif int que_next(void); /* from cque.c */ -extern int on_second; /**< Are we ready to do per-second processing? */ void dispatch(void); /* from timer.c */ dbref email_register_player(const char *name, const char *email, const char *host, const char *ip); /* from player.c */ -extern time_t start_time; /**< When was the mush last rebooted? */ -extern time_t first_start_time; /**< When was the mush first started? */ -extern int reboot_count; /**< How many times have we been rebooted? */ -extern int database_loaded; /* From game.c */ static int extrafd; int shutdown_flag = 0; /**< Is it time to shut down? */ -extern int paranoid_dump; /**< Are we doing a paranoid dump? */ #ifdef CHAT_SYSTEM void chat_player_announce(dbref player, char *msg, int ungag); #endif /* CHAT_SYSTEM */ @@ -409,7 +403,6 @@ void WIN32_CDECL signal_shutdown(int sig); void WIN32_CDECL signal_dump(int sig); void reaper(int sig); extern Pid_t forked_dump_pid; /**< Process id of forking dump process */ -extern time_t last_dump_time; /**< Time of last database dump */ static void dump_users(DESC *call_by, char *match, int doing); static const char *time_format_1(long int dt); static const char *time_format_2(long int dt); @@ -629,7 +622,7 @@ main(int argc, char **argv) init_game_postdb(confname); - database_loaded = 1; + globals.database_loaded = 1; set_signals(); @@ -1061,7 +1054,7 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) last_slice.tv_usec = current_time.tv_usec; if (msec_diff(¤t_time, &then) >= 1000) { - on_second = 1; + globals.on_second = 1; then.tv_sec = current_time.tv_sec; then.tv_usec = current_time.tv_usec; } @@ -1078,7 +1071,7 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) } if (signal_dump_flag) { - paranoid_dump = 0; + globals.paranoid_dump = 0; do_rawlog(LT_CHECK, "DUMP by external signal"); fork_and_dump(1); signal_dump_flag = 0; @@ -3429,7 +3422,7 @@ reaper(int sig __attribute__ ((__unused__))) do_rawlog(LT_ERR, T("ERROR! forking dump exited with signal %d"), WTERMSIG(my_stat)); } else if (WIFEXITED(my_stat) && WEXITSTATUS(my_stat) == 0) { - time(&last_dump_time); + time(&globals.last_dump_time); if (DUMP_NOFORK_COMPLETE && *DUMP_NOFORK_COMPLETE) flag_broadcast(0, 0, "%s", DUMP_NOFORK_COMPLETE); @@ -3460,7 +3453,7 @@ dump_info(DESC *call_by) } queue_string_eol(call_by, tprintf("Name: %s", options.mud_name)); queue_string_eol(call_by, - tprintf("Uptime: %s", show_time(first_start_time, 0))); + tprintf("Uptime: %s", show_time(globals.first_start_time, 0))); queue_string_eol(call_by, tprintf("Connected: %d", count)); queue_string_eol(call_by, tprintf("Size: %d", db_top)); queue_string_eol(call_by, tprintf("Version: CobraMUSH v%s [%s]", VERSION, @@ -4962,8 +4955,8 @@ dump_reboot_db(void) putref(f, 0); putstring(f, poll_msg); - putref(f, first_start_time); - putref(f, reboot_count); + putref(f, globals.first_start_time); + putref(f, globals.reboot_count); fclose(f); } } @@ -5134,8 +5127,8 @@ load_reboot_db(void) } strcpy(poll_msg, getstring_noalloc(f)); - first_start_time = getref(f); - reboot_count = getref(f) + 1; + globals.first_start_time = getref(f); + globals.reboot_count = getref(f) + 1; DESC_ITER_CONN(d) { d->mailp = find_exact_starting_point(d->player); } diff --git a/src/console.c b/src/console.c index b54147a..ed58bf5 100644 --- a/src/console.c +++ b/src/console.c @@ -135,17 +135,11 @@ void rusage_stats(void); #endif int que_next(void); /* from cque.c */ -extern int on_second; /**< Are we ready to do per-second processing? */ void dispatch(void); /* from timer.c */ dbref email_register_player(const char *name, const char *email, const char *host, const char *ip); /* from player.c */ -extern time_t start_time; /**< When was the mush last rebooted? */ -extern time_t first_start_time; /**< When was the mush first started? */ -extern int reboot_count; /**< How many times have we been rebooted? */ -extern int database_loaded; /* From game.c */ static int extrafd; int shutdown_flag = 0; /**< Is it time to shut down? */ -extern int paranoid_dump; /**< Are we doing a paranoid dump? */ #ifdef CHAT_SYSTEM void chat_player_announce(dbref player, char *msg, int ungag); #endif /* CHAT_SYSTEM */ @@ -367,7 +361,6 @@ void WIN32_CDECL signal_shutdown(int sig); void WIN32_CDECL signal_dump(int sig); void reaper(int sig); extern Pid_t forked_dump_pid; /**< Process id of forking dump process */ -extern time_t last_dump_time; /**< Time of last database dump */ static void dump_users(DESC *call_by, char *match, int doing); static const char *time_format_1(long int dt); static const char *time_format_2(long int dt); @@ -580,7 +573,7 @@ main(int argc, char **argv) init_game_postdb(confname); - database_loaded = 1; + globals.database_loaded = 1; set_signals(); @@ -972,7 +965,7 @@ shovechars() last_slice.tv_usec = current_time.tv_usec; if (msec_diff(¤t_time, &then) >= 1000) { - on_second = 1; + globals.on_second = 1; then.tv_sec = current_time.tv_sec; then.tv_usec = current_time.tv_usec; } @@ -989,7 +982,7 @@ shovechars() } if (signal_dump_flag) { - paranoid_dump = 0; + globals.paranoid_dump = 0; do_rawlog(LT_CHECK, "DUMP by external signal"); fork_and_dump(1); signal_dump_flag = 0; @@ -2721,7 +2714,7 @@ reaper(int sig __attribute__ ((__unused__))) do_rawlog(LT_ERR, T("ERROR! forking dump exited with signal %d"), WTERMSIG(my_stat)); } else if (WIFEXITED(my_stat) && WEXITSTATUS(my_stat) == 0) { - time(&last_dump_time); + time(&globals.last_dump_time); if (DUMP_NOFORK_COMPLETE && *DUMP_NOFORK_COMPLETE) flag_broadcast(0, 0, "%s", DUMP_NOFORK_COMPLETE); @@ -2752,7 +2745,7 @@ dump_info(DESC *call_by) } queue_string_eol(call_by, tprintf("Name: %s", options.mud_name)); queue_string_eol(call_by, - tprintf("Uptime: %s", show_time(first_start_time, 0))); + tprintf("Uptime: %s", show_time(globals.first_start_time, 0))); queue_string_eol(call_by, tprintf("Connected: %d", count)); queue_string_eol(call_by, tprintf("Size: %d", db_top)); queue_string_eol(call_by, tprintf("Version: CobraMUSH v%s [%s]", VERSION, @@ -4132,8 +4125,8 @@ dump_reboot_db(void) putref(f, 0); putstring(f, poll_msg); - putref(f, first_start_time); - putref(f, reboot_count); + putref(f, globals.first_start_time); + putref(f, globals.reboot_count); fclose(f); } } @@ -4298,8 +4291,8 @@ load_reboot_db(void) } strcpy(poll_msg, getstring_noalloc(f)); - first_start_time = getref(f); - reboot_count = getref(f) + 1; + globals.first_start_time = getref(f); + globals.reboot_count = getref(f) + 1; DESC_ITER_CONN(d) { d->mailp = find_exact_starting_point(d->player); } diff --git a/src/db.c b/src/db.c index 929d3ff..3334175 100644 --- a/src/db.c +++ b/src/db.c @@ -48,8 +48,6 @@ void shutdown_checkpoint(void); #define MAYBE_GET(f,x) \ (indb_flags & (x)) ? getref(f) : 0 -extern int paranoid_checkpt; /* from game.c */ - long indb_flags; /**< What flags are in the db we read at startup? */ long flagdb_flags; /**< What flags are in the flag db we read at startup? */ @@ -940,7 +938,7 @@ db_paranoid_write(FILE * f, int flag) OUTPUT(fprintf(f, "!%d\n", i)); db_paranoid_write_object(f, i, flag); /* print out a message every so many objects */ - if (i % paranoid_checkpt == 0) + if (i % globals.paranoid_checkpt == 0) do_rawlog(LT_CHECK, T("\t...wrote up to object #%d\n"), i); } OUTPUT(fputs(EOD, f)); @@ -1977,12 +1975,10 @@ init_objdata_htab(int size) hashinit(&htab_objdata_keys, 8, 32); } -extern time_t first_start_time; - void init_postconvert() { dbref master_division, i; - if((!(indb_flags & DBF_DIVISIONS) || (indb_flags & DBF_TYPE_GARBAGE)) && CreTime(0) != first_start_time ) { + if((!(indb_flags & DBF_DIVISIONS) || (indb_flags & DBF_TYPE_GARBAGE)) && CreTime(0) != globals.first_start_time ) { do_rawlog(LT_ERR, "Beginning Pennmush to CobraMUSH database conversion process."); /* Final Step of DB Conversion * We're gonna first Create the Master Division diff --git a/src/funmisc.c b/src/funmisc.c index 81b415b..738699d 100644 --- a/src/funmisc.c +++ b/src/funmisc.c @@ -34,8 +34,6 @@ #pragma warning( disable : 4761) /* NJG: disable warning re conversion */ #endif -extern time_t start_time, first_start_time; -extern int reboot_count; extern FUN flist[]; static char *soundex(char *str); extern char cf_motd_msg[BUFFER_LEN], @@ -429,19 +427,19 @@ FUNCTION(fun_version) /* ARGSUSED */ FUNCTION(fun_starttime) { - safe_str(show_time(first_start_time, 0), buff, bp); + safe_str(show_time(globals.first_start_time, 0), buff, bp); } /* ARGSUSED */ FUNCTION(fun_restarttime) { - safe_str(show_time(start_time, 0), buff, bp); + safe_str(show_time(globals.start_time, 0), buff, bp); } /* ARGSUSED */ FUNCTION(fun_restarts) { - safe_integer(reboot_count, buff, bp); + safe_integer(globals.reboot_count, buff, bp); } /* Data for soundex functions */ diff --git a/src/game.c b/src/game.c index ddba758..e3adc1d 100644 --- a/src/game.c +++ b/src/game.c @@ -92,12 +92,7 @@ void Win32MUSH_setup(void); #endif /* declarations */ -int database_loaded = 0; /**< True after the database has been read. */ -char dumpfile[200]; /**< File name to dump database to */ -time_t start_time; /**< MUSH start time (since process exec'd) */ -time_t first_start_time = 0; /**< MUSH start time (since last shutdown) */ -time_t last_dump_time = 0; /**< Time of last successful db save */ -int reboot_count = 0; /**< Number of reboots so far */ +GLOBALTAB globals = { 0, "", 0, 0, 0, 0, 0, 0, 0, 0 }; static int epoch = 0; static int reserved; /**< Reserved file descriptor */ int depth = 0; /**< excessive recursion prevention */ @@ -110,9 +105,6 @@ static void errdb_grow(void); extern void initialize_mt(void); extern const unsigned char *tables; -int paranoid_dump = 0; /**< if paranoid, scan before dumping */ -int paranoid_checkpt = 0; /**< write out an okay message every x objs */ -extern long indb_flags; extern void conf_default_set(void); static int dump_database_internal(void); static FILE *db_open(const char *filename); @@ -200,45 +192,46 @@ do_dump(dbref player, char *num, enum dump_type flag) if (flag != DUMP_NORMAL) { #endif /* want to do a scan before dumping each object */ - paranoid_dump = 1; + globals.paranoid_dump = 1; if (num && *num) { /* checkpoint interval given */ - paranoid_checkpt = atoi(num); - if ((paranoid_checkpt < 1) || (paranoid_checkpt >= db_top)) { + globals.paranoid_checkpt = atoi(num); + if ((globals.paranoid_checkpt < 1) + || (globals.paranoid_checkpt >= db_top)) { notify(player, T("Permission denied. Invalid checkpoint interval.")); - paranoid_dump = 0; + globals.paranoid_dump = 0; return; } } else { /* use a default interval */ - paranoid_checkpt = db_top / 5; - if (paranoid_checkpt < 1) - paranoid_checkpt = 1; + globals.paranoid_checkpt = db_top / 5; + if (globals.paranoid_checkpt < 1) + globals.paranoid_checkpt = 1; } if (flag == DUMP_PARANOID) { notify_format(player, T("Paranoid dumping, checkpoint interval %d."), - paranoid_checkpt); + globals.paranoid_checkpt); do_rawlog(LT_CHECK, "*** PARANOID DUMP *** done by %s(#%d),\n", Name(player), player); } else { notify_format(player, T("Debug dumping, checkpoint interval %d."), - paranoid_checkpt); + globals.paranoid_checkpt); do_rawlog(LT_CHECK, "*** DEBUG DUMP *** done by %s(#%d),\n", Name(player), player); } do_rawlog(LT_CHECK, T("\tcheckpoint interval %d, at %s"), - paranoid_checkpt, show_time(mudtime, 0)); + globals.paranoid_checkpt, show_time(mudtime, 0)); } else { /* normal dump */ - paranoid_dump = 0; /* just to be safe */ + globals.paranoid_dump = 0; /* just to be safe */ notify(player, "Dumping..."); do_rawlog(LT_CHECK, "** DUMP ** done by %s(#%d) at %s", Name(player), player, show_time(mudtime, 0)); } fork_and_dump(1); - paranoid_dump = 0; + globals.paranoid_dump = 0; } } @@ -320,10 +313,10 @@ do_shutdown(dbref player, enum shutdown_type flag) mush_panic("@shutdown/panic"); } else { if (flag == SHUT_PARANOID) { - paranoid_checkpt = db_top / 5; - if (paranoid_checkpt < 1) - paranoid_checkpt = 1; - paranoid_dump = 1; + globals.paranoid_checkpt = db_top / 5; + if (globals.paranoid_checkpt < 1) + globals.paranoid_checkpt = 1; + globals.paranoid_dump = 1; } shutdown_flag = 1; } @@ -385,12 +378,12 @@ dump_database_internal(void) } } - sprintf(realdumpfile, "%s%s", dumpfile, options.compresssuff); - strcpy(tmpfl, make_new_epoch_file(dumpfile, epoch)); + sprintf(realdumpfile, "%s%s", globals.dumpfile, options.compresssuff); + strcpy(tmpfl, make_new_epoch_file(globals.dumpfile, epoch)); sprintf(realtmpfl, "%s%s", tmpfl, options.compresssuff); if ((f = db_open_write(tmpfl)) != NULL) { - switch (paranoid_dump) { + switch (globals.paranoid_dump) { case 0: #ifdef ALWAYS_PARANOID db_paranoid_write(f, 0); @@ -456,7 +449,7 @@ dump_database_internal(void) longjmp(db_err, 1); } #endif /* CHAT_SYSTEM */ - time(&last_dump_time); + time(&globals.last_dump_time); } #endif @@ -503,7 +496,7 @@ mush_panic(const char *message) emergency_shutdown(); /* dump panic file if we have a database read. */ - if (database_loaded) { + if (globals.database_loaded) { if (setjmp(db_err)) { /* Dump failed. We're in deep doo-doo */ do_rawlog(LT_ERR, T("CANNOT DUMP PANIC DB. OOPS.")); @@ -566,9 +559,9 @@ dump_database(void) { epoch++; - do_rawlog(LT_ERR, "DUMPING: %s.#%d#", dumpfile, epoch); + do_rawlog(LT_ERR, "DUMPING: %s.#%d#", globals.dumpfile, epoch); dump_database_internal(); - do_rawlog(LT_ERR, "DUMPING: %s.#%d# (done)", dumpfile, epoch); + do_rawlog(LT_ERR, "DUMPING: %s.#%d# (done)", globals.dumpfile, epoch); } /** Dump a database, possibly by forking the process. @@ -593,11 +586,11 @@ fork_and_dump(int forking) chunk_stats(NOTHING, 0); chunk_stats(NOTHING, 1); #endif - do_rawlog(LT_CHECK, "CHECKPOINTING: %s.#%d#\n", dumpfile, epoch); + do_rawlog(LT_CHECK, "CHECKPOINTING: %s.#%d#\n", globals.dumpfile, epoch); if (NO_FORK) nofork = 1; else - nofork = !forking || (paranoid_dump == 2); /* Don't fork for dump/debug */ + nofork = !forking || (globals.paranoid_dump == 2); /* Don't fork for dump/debug */ #ifdef WIN32 nofork = 1; #endif @@ -766,9 +759,9 @@ init_game_config(const char *conf) } /* set MUSH start time */ - start_time = time((time_t *) 0); - if (!first_start_time) - first_start_time = start_time; + globals.start_time = time((time_t *) 0); + if (!globals.first_start_time) + globals.first_start_time = globals.start_time; /* initialize all the hash and prefix tables */ init_flagspaces(); @@ -797,7 +790,7 @@ init_game_config(const char *conf) do_rawlog(LT_ERR, "CobraMUSH v%s [%s]", VERSION, VBRANCH); do_rawlog(LT_ERR, T("MUSH restarted, PID %d, at %s"), - (int) getpid(), show_time(start_time, 0)); + (int) getpid(), show_time(globals.start_time, 0)); } /** Post-db-load configuration. @@ -871,7 +864,7 @@ init_game_dbs(void) outfile = options.output_db; flag_file = options.flagdb; mailfile = options.mail_db; - strcpy(dumpfile, outfile); + strcpy(globals.dumpfile, outfile); /* read small text files into cache */ fcache_init(); @@ -942,7 +935,7 @@ init_game_dbs(void) * format db, with everything shoved together. In that case, * don't close the file */ - panicdb = ((indb_flags & DBF_PANIC) && !feof(f)); + panicdb = ((globals.indb_flags & DBF_PANIC) && !feof(f)); if (!panicdb) db_close(f); @@ -2194,22 +2187,22 @@ do_uptime(dbref player, int mortal) char tbuf1[BUFFER_LEN]; struct tm *when; - when = localtime(&first_start_time); + when = localtime(&globals.first_start_time); strftime(tbuf1, sizeof tbuf1, T(" Up since %a %b %d %X %Z %Y"), when); notify(player, tbuf1); - when = localtime(&start_time); + when = localtime(&globals.start_time); strftime(tbuf1, sizeof tbuf1, T(" Last reboot: %a %b %d %X %Z %Y"), when); notify(player, tbuf1); - notify_format(player, T("Total reboots: %d"), reboot_count); + notify_format(player, T("Total reboots: %d"), globals.reboot_count); when = localtime(&mudtime); strftime(tbuf1, sizeof tbuf1, T(" Time now: %a %b %d %X %Z %Y"), when); notify(player, tbuf1); - if (last_dump_time > 0) { - when = localtime(&last_dump_time); + if (globals.last_dump_time > 0) { + when = localtime(&globals.last_dump_time); strftime(tbuf1, sizeof tbuf1, T(" Time of last database save: %a %b %d %X %Z %Y"), when); notify(player, tbuf1); diff --git a/src/timer.c b/src/timer.c index cbb866f..e66fa4f 100644 --- a/src/timer.c +++ b/src/timer.c @@ -42,7 +42,6 @@ #include "confmagic.h" -int on_second = 0; /**< Have we been called at the end of a second? */ static sig_atomic_t hup_triggered = 0; static sig_atomic_t usr1_triggered = 0; @@ -219,9 +218,9 @@ dispatch(void) do_reboot(NOTHING, 0); /* We don't return from this */ usr1_triggered = 0; /* But just in case */ } - if (!on_second) + if (!globals.on_second) return; - on_second = 0; + globals.on_second = 0; mudtime = time(NULL); diff --git a/src/version.c b/src/version.c index 3d0d909..095e388 100644 --- a/src/version.c +++ b/src/version.c @@ -21,7 +21,6 @@ #endif #include "confmagic.h" -extern time_t start_time; /* from bsd.c */ void do_version _((dbref player)); void @@ -32,7 +31,7 @@ do_version(player) notify_format(player, T("You are connected to %s"), MUDNAME); - strcpy(buff, ctime(&start_time)); + strcpy(buff, ctime(&globals.start_time)); buff[strlen(buff) - 1] = '\0'; /* eat the newline */ notify_format(player, T("Last restarted: %s"), buff); diff --git a/src/wiz.c b/src/wiz.c index 7281a9d..f1d2b04 100644 --- a/src/wiz.c +++ b/src/wiz.c @@ -51,8 +51,6 @@ extern dbref find_entrance(dbref door); struct db_stat_info *get_stats(dbref owner); extern dbref find_player_by_desc(int port); -extern int paranoid_dump; -extern int paranoid_checkpt; #ifndef WIN32 @@ -2054,10 +2052,10 @@ do_reboot(dbref player, int flag) Name(Owner(player))); } if (flag) { - paranoid_dump = 1; - paranoid_checkpt = db_top / 5; - if (paranoid_checkpt < 1) - paranoid_checkpt = 1; + globals.paranoid_dump = 1; + globals.paranoid_checkpt = db_top / 5; + if (globals.paranoid_checkpt < 1) + globals.paranoid_checkpt = 1; } #ifdef HAS_OPENSSL close_ssl_connections();