From: Ari Johnson Date: Tue, 19 Apr 2011 04:58:01 +0000 (-0400) Subject: For console mode, dup() stdin and stdout earlier to avoid their being closed X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=9bedbeb706c48027d78f284bf868f7dabf340875;p=cobramush.git For console mode, dup() stdin and stdout earlier to avoid their being closed --- diff --git a/src/bsd.c b/src/bsd.c index be82561..d26581c 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -275,6 +275,7 @@ DESC *descriptor_list = NULL; /**< The linked list of descriptors */ intmap *descs_by_fd = NULL; /**< Map of ports to DESC* objects */ static bool console_mode = 0; +static int console_input, console_output; static int sock = 0; #ifdef HAS_OPENSSL static int sslsock = 0; @@ -505,6 +506,8 @@ 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], "--pid-file", 10) == 0) { char *eq; if ((eq = strchr(argv[n], '='))) @@ -1007,17 +1010,14 @@ shovechars(Port_t port __attribute__ ((__unused__)), int avail_descriptors; unsigned long input_ready, output_ready; int notify_fd = -1; - int infd, outfd; if (console_mode) { - infd = dup(STDIN_FILENO); - outfd = dup(STDOUT_FILENO); - if (infd >= maxd) - maxd = infd + 1; - if (outfd >= maxd) - maxd = outfd + 1; - - d = initializesock(infd, outfd, "localhost", "127.0.0.1", 0); + if (console_input >= maxd) + maxd = console_input + 1; + if (console_output >= maxd) + maxd = console_output + 1; + + d = initializesock(console_input, console_output, "localhost", "127.0.0.1", 0); sock = 0; #ifdef HAS_OPENSSL