From 1a3e1ab15e9cd374116c4a17a3ea5cc757e36d2c Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Sat, 23 Apr 2011 14:36:31 -0400 Subject: [PATCH] Change OUTDESC flag in reboot.db to CONSOLE to better reflect purpose; fix @shutdown/reboot in console mode --- hdrs/mushdb.h | 2 +- src/bsd.c | 80 +++++++++++++++++++++++++++++---------------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/hdrs/mushdb.h b/hdrs/mushdb.h index 1ab7c4a..fb92648 100644 --- a/hdrs/mushdb.h +++ b/hdrs/mushdb.h @@ -243,6 +243,6 @@ bool unfindable(dbref); #define RDBF_PUEBLO_CHECKSUM 0x04 /* Available: 0x08 - 0x8000 */ #define RDBF_SU_EXIT_PATH 0x00010000 -#define RDBF_OUTDESC 0x00020000 +#define RDBF_CONSOLE 0x00020000 #endif /* __DB_H */ diff --git a/src/bsd.c b/src/bsd.c index a67e4d3..197261f 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -507,16 +507,12 @@ main(int argc, char **argv) else if (strcmp(argv[n], "--console") == 0) { console_mode = 1; detach_session = 0; - console_input = dup(STDIN_FILENO); - console_output = dup(STDOUT_FILENO); } else if(strncmp(argv[n], "--user",6) == 0) { fprintf(stderr, "USING USER OPTION\n"); if ((eq = strchr(argv[n], '='))) { console_user = eq + 1; console_mode = 1; detach_session = 0; - console_input = dup(STDIN_FILENO); - console_output = dup(STDOUT_FILENO); } else { if (n + 1 >= argc) { fprintf(stderr, "%s: --user needs a user to log into.\n", argv[0]); @@ -527,8 +523,6 @@ main(int argc, char **argv) /* Assume console mode & non-session */ console_mode = 1; detach_session = 0; - console_input = dup(STDIN_FILENO); - console_output = dup(STDOUT_FILENO); } } else if (strncmp(argv[n], "--pid-file", 10) == 0) { if ((eq = strchr(argv[n], '='))) @@ -661,6 +655,21 @@ main(int argc, char **argv) * Eventually we'll conver the config file to a big lua script, so we'll start the lua envionrment before it */ mush_lua_start(); + /* decide if we're in @shutdown/reboot + * This has to be done before init_game_config() to avoid stdin and stdout + * being closed before we need them. */ + restarting = 0; + newerr = fopen(REBOOTFILE, "r"); + if (newerr) { + restarting = 1; + fclose(newerr); + } + + if (console_mode && !restarting) { + console_input = dup(STDIN_FILENO); + console_output = dup(STDOUT_FILENO); + } + init_game_config(confname); /* save a file descriptor */ @@ -669,14 +678,6 @@ main(int argc, char **argv) extrafd = open("/dev/null", O_RDWR); #endif - /* decide if we're in @shutdown/reboot */ - restarting = 0; - newerr = fopen(REBOOTFILE, "r"); - if (newerr) { - restarting = 1; - fclose(newerr); - } - /* load databases */ if (init_game_dbs() < 0) { do_rawlog(LT_ERR, T("ERROR: Couldn't load databases! Exiting.")); @@ -1031,30 +1032,32 @@ shovechars(Port_t port __attribute__ ((__unused__)), unsigned long input_ready, output_ready; int notify_fd = -1; - if (console_mode) { - if (console_input >= maxd) - maxd = console_input + 1; - if (console_output >= maxd) - maxd = console_output + 1; + if (!restarting) { + if (console_mode) { + if (console_input >= maxd) + maxd = console_input + 1; + if (console_output >= maxd) + maxd = console_output + 1; - initializesock(console_input, console_output, "localhost", "127.0.0.1", 0); + initializesock(console_input, console_output, "localhost", "127.0.0.1", 0); - sock = 0; + sock = 0; #ifdef HAS_OPENSSL - sslsock = 0; + sslsock = 0; #endif - } else if (!restarting) { - sock = make_socket(port, SOCK_STREAM, NULL, NULL, MUSH_IP_ADDR); - if (sock >= maxd) - maxd = sock + 1; + } else { + sock = make_socket(port, SOCK_STREAM, NULL, NULL, MUSH_IP_ADDR); + if (sock >= maxd) + maxd = sock + 1; #ifdef HAS_OPENSSL - if (sslport) { - sslsock = make_socket(sslport, SOCK_STREAM, NULL, NULL, SSL_IP_ADDR); - ssl_master_socket = ssl_setup_socket(sslsock); - if (sslsock >= maxd) - maxd = sslsock + 1; - } + if (sslport) { + sslsock = make_socket(sslport, SOCK_STREAM, NULL, NULL, SSL_IP_ADDR); + ssl_master_socket = ssl_setup_socket(sslsock); + if (sslsock >= maxd) + maxd = sslsock + 1; + } #endif + } } our_gettimeofday(&last_slice); @@ -4811,7 +4814,7 @@ dump_reboot_db(void) DESC *d; SU_PATH *exit_path; long flags = RDBF_SCREENSIZE | RDBF_TTYPE | RDBF_PUEBLO_CHECKSUM - | RDBF_SU_EXIT_PATH | RDBF_OUTDESC; + | RDBF_SU_EXIT_PATH | RDBF_CONSOLE; if (setjmp(db_err)) { flag_broadcast(0, 0, T("GAME: Error writing reboot database!")); exit(0); @@ -4827,6 +4830,8 @@ dump_reboot_db(void) penn_fprintf(f, "V%ld\n", flags); putref(f, sock); putref(f, maxd); + putref(f, console_input); + putref(f, console_output); /* First, iterate through all descriptors to get to the end * we do this so the descriptor_list isn't reversed on reboot */ @@ -4915,11 +4920,16 @@ load_reboot_db(void) if (val > maxd) maxd = val; + if (flags & RDBF_CONSOLE) { + console_input = getref(f); + console_output = getref(f); + } + while ((val = getref(f)) != 0) { ndescriptors++; d = (DESC *) mush_malloc(sizeof(DESC), "descriptor"); d->descriptor = val; - if (flags & RDBF_OUTDESC) + if (flags & RDBF_CONSOLE) d->outdesc = getref(f); d->input_handler = do_command; d->connected_at = getref(f); @@ -5493,6 +5503,8 @@ do_reboot(dbref player, int flag) args[n++] = saved_argv[0]; args[n++] = "--no-session"; + if (console_mode) + args[n++] = "--console"; if (pidfile) { args[n++] = "--pid-file"; args[n++] = pidfile; -- 2.30.2