Subject: An improvment to ipfstat -t state top
To: None <netbsd-users@netbsd.org>
From: John <from_netbsd4@frear.com>
List: netbsd-users
Date: 04/05/2004 23:19:20
Hi,
I want to share a modification I made to my netbsd system with the
public. A while ago I ran "ipfstat -t" and let it run for a while, then I
closed the terminal window without hitting 'q' to gracefully exit the
program. A little while later, I noticed ipfstat was still running and
was cpu bound.
This seems to be related to the curses interface not returning a
proper status code for the printw function, and the fils.c code not
checking for a return code anyway. printw returns ERR upon error, however
if I close the terminal this doesn't seem to be considered an error. I
searched for a way to check for a closed terminal window using the curses
library, but I can't find one so I used isatty from the std C library. I
thnk its portable and won't interfere with curses during normal operation.
This change was made against dist/ipf/fils.c version 1.16.2.2.
I hope people find this modification useful.
- John
<from_netbsd4@frear.com>
--- dist/ipf/fils.c.orig Wed Mar 24 19:43:30 2004
+++ dist/ipf/fils.c Mon Apr 5 22:46:42 2004
@@ -963,6 +963,14 @@
/* repeat until user aborts */
while ( 1 ) {
+ /* Check to make sure the user has not closed the terminal
+ * window. Without this check, closing the terminal window
+ * on 'ipfstat -t' causes the program to go into a cpu bound
+ * loop.
+ */
+ if( isatty( 0 ) != 1 )
+ break;
+
/* get state table */
bzero((char *)&ipsst, sizeof(&ipsst));
if ((ioctl(sfd, SIOCGETFS, &ipsstp) == -1)) {