Nmap Development mailing list archives
[PATCH] Reconnect terminal in tty_getchar() under an else{} in nmap_tty.cc
From: Kris Katterjohn <kjak () ispwest com>
Date: Fri, 01 Sep 2006 11:38:56 -0500
The attached patch removes the commented-out part of tty_getchar() which called tty_init() and makes an else branch to call tty_init() if we can't access the terminal. tty_done() is called just to be safe; the worst case is just an extra return. It's a diff against 4.20ALPHA5 Thanks, Kris Katterjohn P.S. This patch has to be applied because it's 1337 bytes long :P
--- x/nmap_tty.cc 2006-08-24 20:47:37.000000000 -0500
+++ y/nmap_tty.cc 2006-09-01 11:24:24.000000000 -0500
@@ -146,6 +146,16 @@ extern int tcsetattr(int fd, int actions
static int tty_fd = 0;
static struct termios saved_ti;
+static void tty_done()
+{
+ if (!tty_fd) return;
+
+ tcsetattr(tty_fd, TCSANOW, &saved_ti);
+
+ close(tty_fd);
+ tty_fd = 0;
+}
+
static int tty_getchar()
{
int c, numChars;
@@ -155,10 +165,6 @@ static int tty_getchar()
#endif
if (tty_fd && tcgetpgrp(tty_fd) == getpid()) {
-
- // This is so that when the terminal has been disconnected, it will be reconnected when possible. If it
slows things down, just remove it
- // tty_init();
-
#ifdef __CYGWIN32__
FD_ZERO(&set); FD_SET(tty_fd, &set);
tv.tv_sec = 0; tv.tv_usec = 0;
@@ -168,21 +174,17 @@ static int tty_getchar()
c = 0;
numChars = read(tty_fd, &c, 1);
if (numChars > 0) return c;
+ } else {
+ tty_done();
+ tty_init();
+
+ if (tty_fd)
+ return tty_getchar();
}
return -1;
}
-static void tty_done()
-{
- if (!tty_fd) return;
-
- tcsetattr(tty_fd, TCSANOW, &saved_ti);
-
- close(tty_fd);
- tty_fd = 0;
-}
-
/*
* Initializes the terminal for unbuffered non-blocking input. Also
* registers tty_done() via atexit(). You need to call this before
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [PATCH] Reconnect terminal in tty_getchar() under an else{} in nmap_tty.cc Kris Katterjohn (Sep 01)
- Re: [PATCH] Reconnect terminal in tty_getchar() under an else{} in nmap_tty.cc Fyodor (Sep 02)
- Re: [PATCH] Reconnect terminal in tty_getchar() under an else{} in nmap_tty.cc Kris Katterjohn (Sep 02)
- Re: [PATCH] Reconnect terminal in tty_getchar() under an else{} in nmap_tty.cc Fyodor (Sep 02)
