Nmap Development mailing list archives
[PATCH] Simplify tty_init() and tty_done() in nmap_tty.cc
From: Kris Katterjohn <kjak () ispwest com>
Date: Tue, 22 Aug 2006 13:14:35 -0500
This simplifies tty_init() and tty_done() in nmap_tty.cc. The extra fd variable isn't needed and just makes it complicated. I've tested it and everything still works okay. It's a diff against 4.20ALPHA4 Thanks, Kris Katterjohn
--- x/nmap_tty.cc 2006-03-08 15:45:01.000000000 -0600
+++ y/nmap_tty.cc 2006-08-22 13:02:43.000000000 -0500
@@ -175,14 +175,12 @@ static int tty_getchar()
static void tty_done()
{
- int fd;
-
if (!tty_fd) return;
- fd = tty_fd; tty_fd = 0;
- tcsetattr(fd, TCSANOW, &saved_ti);
+ tcsetattr(tty_fd, TCSANOW, &saved_ti);
- close(fd);
+ close(tty_fd);
+ tty_fd = 0;
}
/*
@@ -192,28 +190,26 @@ static void tty_done()
*/
void tty_init()
{
- int fd;
struct termios ti;
- if ((fd = open("/dev/tty", O_RDONLY | O_NONBLOCK)) < 0) return;
+ if (tty_fd)
+ return;
+
+ if ((tty_fd = open("/dev/tty", O_RDONLY | O_NONBLOCK)) < 0) return;
#ifndef __CYGWIN32__
- if (tcgetpgrp(fd) != getpid()) {
- close(fd); return;
+ if (tcgetpgrp(tty_fd) != getpid()) {
+ close(tty_fd); return;
}
#endif
- tcgetattr(fd, &ti);
- if (tty_fd == 0)
- saved_ti = ti;
+ tcgetattr(tty_fd, &ti);
+ saved_ti = ti;
ti.c_lflag &= ~(ICANON | ECHO);
ti.c_cc[VMIN] = 1;
ti.c_cc[VTIME] = 0;
- tcsetattr(fd, TCSANOW, &ti);
+ tcsetattr(tty_fd, TCSANOW, &ti);
- if (tty_fd == 0)
- tty_fd = fd;
-
atexit(tty_done);
}
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [PATCH] Simplify tty_init() and tty_done() in nmap_tty.cc Kris Katterjohn (Aug 22)
- Re: [PATCH] Simplify tty_init() and tty_done() in nmap_tty.cc Fyodor (Aug 22)
