From: Ari Johnson Date: Mon, 18 Apr 2011 04:53:28 +0000 (-0400) Subject: More work on re-enabling console X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=81fce7741a7cc84601fd788172570efe4a98503c;p=cobramush.git More work on re-enabling console --- diff --git a/src/bsd.c b/src/bsd.c index 17b36c5..8365ca4 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -479,7 +479,11 @@ main(int argc, char **argv) FILE *id; #endif FILE *newerr; +#ifdef COMPILE_CONSOLE + bool detach_session = 0; +#else bool detach_session = 1; +#endif struct module_entry_t *m; void (*handle)(); @@ -1024,20 +1028,20 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) int queue_timeout; DESC *d, *dnext; #ifndef COMPILE_CONSOLE - int avail_descriptors; #ifdef INFO_SLAVE union sockaddr_u addr; socklen_t addr_len; int newsock; #endif + int avail_descriptors; #endif /* COMPILE_CONSOLE */ unsigned long input_ready, output_ready; int notify_fd = -1; #ifdef COMPILE_CONSOLE d = initializesock(0, "localhost", "127.0.0.1", 0); - if (STDIN_FILENO >= maxd) - maxd = STDIN_FILENO + 1; + if (2 >= maxd) + maxd = 3; #else if (!restarting) { sock = make_socket(port, SOCK_STREAM, NULL, NULL, MUSH_IP_ADDR); @@ -1281,6 +1285,30 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) for (d = descriptor_list; d; d = dnext) { dnext = d->next; +#ifdef COMPILE_CONSOLE + if (d->descriptor == 0) { + input_ready = FD_ISSET(STDIN_FILENO, &input_set); + output_ready = FD_ISSET(STDOUT_FILENO, &output_set); + } else { + input_ready = FD_ISSET(d->descriptor, &input_set); + output_ready = FD_ISSET(d->descriptor, &output_set); + } + if (input_ready) { + if (!process_input(d, output_ready)) { + shutdownsock(d); + if(d->descriptor == 0) + return; + continue; + } + } + if (output_ready) { + if (!process_output(d)) { + shutdownsock(d); + if (d->descriptor == 0) + return; + } + } +#else /* COMPILE_CONSOLE */ input_ready = FD_ISSET(d->descriptor, &input_set); output_ready = FD_ISSET(d->descriptor, &output_set); if (input_ready) { @@ -1294,6 +1322,7 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) shutdownsock(d); } } +#endif /* COMPILE_CONSOLE */ } } } @@ -1920,6 +1949,11 @@ process_output(DESC *d) #endif /* COMPILE_CONSOLE */ for (qp = &d->output.head; ((cur = *qp) != NULL);) { +#ifdef COMPILE_CONSOLE + if (d->descriptor == 0) + cnt = write(STDOUT_FILENO, cur->start, cur->nchars); + else { +#else /* COMPILE_CONSOLE */ #ifdef HAVE_WRITEV if (cur->nxt #ifdef HAVE_SSL @@ -1989,7 +2023,6 @@ process_output(DESC *d) } } else { #endif /* HAVE_WRITEV */ -#ifndef COMPILE_CONSOLE #ifdef HAS_OPENSSL if (d->ssl) { cnt = 0; @@ -2954,7 +2987,18 @@ close_sockets(void) for (d = descriptor_list; d; d = dnext) { dnext = d->next; -#ifndef COMPILE_CONSOLE +#ifdef COMPILE_CONSOLE + if(d->descriptor == 0) { + write(STDOUT_FILENO, T(shutdown_message), strlen(T(shutdown_message))); + write(STDOUT_FILENO, "\r\n", 2); + } else { + send(d->descriptor, T(shutdown_message), strlen(T(shutdown_message)), 0); + send(d->descriptor, "\r\n", 2, 0); + if (shutdown(d->descriptor, 2) < 0) + perror("shutdown"); + closesocket(d->descriptor); + } +#else /* COMPILE_CONSOLE */ #ifdef HAS_OPENSSL if (!d->ssl) { #endif