telnet: move winsize detection closer to I/O loop, delete non-functioning debug code
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 7 Apr 2018 13:02:20 +0000 (15:02 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 7 Apr 2018 13:02:20 +0000 (15:02 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/bb_askpass.c
networking/telnet.c

index aae35ec41af209834f7134ba812539b12536c4a0..5599c82ef982b8bf7e6aebb411f2b13ae585f225 100644 (file)
@@ -37,15 +37,6 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
 
        tcgetattr(fd, &oldtio);
        tio = oldtio;
-#if 0
-       /* Switch off UPPERCASE->lowercase conversion (never used since 198x)
-        * and XON/XOFF (why we want to mess with this??)
-        */
-# ifndef IUCLC
-#  define IUCLC 0
-# endif
-       tio.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY);
-#endif
        /* Switch off echo */
        tio.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL);
        tcsetattr(fd, TCSANOW, &tio);
@@ -66,9 +57,8 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
        while (1) {
                int r = read(fd, &ret[i], 1);
                if ((i == 0 && r == 0) /* EOF (^D) with no password */
-                || r < 0
+                || r < 0 /* read is interrupted by timeout or ^C */
                ) {
-                       /* read is interrupted by timeout or ^C */
                        ret = NULL;
                        break;
                }
index 8b0df7f5c4f0211304b3d87ac5531ac180179883..15d6a08d8288408566bc71bef1a6e17a7c22db31 100644 (file)
 # define TELOPT_NAWS  31  /* window size */
 #endif
 
-#ifdef DOTRACE
-# define TRACE(x, y) do { if (x) printf y; } while (0)
-#else
-# define TRACE(x, y)
-#endif
-
 enum {
        DATABUFSIZE = 128,
        IACBUFSIZE  = 128,
@@ -627,10 +621,6 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
 
        INIT_G();
 
-#if ENABLE_FEATURE_TELNET_WIDTH
-       get_terminal_width_height(0, &G.win_width, &G.win_height);
-#endif
-
 #if ENABLE_FEATURE_TELNET_TTYPE
        G.ttype = getenv("TERM");
 #endif
@@ -661,6 +651,11 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
 
        setsockopt_keepalive(netfd);
 
+#if ENABLE_FEATURE_TELNET_WIDTH
+       get_terminal_width_height(0, &G.win_width, &G.win_height);
+//TODO: support dynamic resize?
+#endif
+
        signal(SIGINT, record_signo);
 
        ufds[0].fd = STDIN_FILENO;
@@ -684,7 +679,6 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
                        len = safe_read(STDIN_FILENO, G.buf, DATABUFSIZE);
                        if (len <= 0)
                                doexit(EXIT_SUCCESS);
-                       TRACE(0, ("Read con: %d\n", len));
                        handle_net_output(len);
                }
 
@@ -694,7 +688,6 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
                                full_write1_str("Connection closed by foreign host\r\n");
                                doexit(EXIT_FAILURE);
                        }
-                       TRACE(0, ("Read netfd (%d): %d\n", netfd, len));
                        handle_net_input(len);
                }
        } /* while (1) */