Subject: bin/36999: systat refresh interval is limited
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <dieter.NetBSD@pandora.be>
List: netbsd-bugs
Date: 09/17/2007 15:25:01
>Number:         36999
>Category:       bin
>Synopsis:       systat refresh interval is limited
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 17 15:25:01 +0000 2007
>Originator:     Dieter Roelants
>Release:        NetBSD 4.0_RC1
>Organization:
>Environment:
System: NetBSD bsdusr.net 4.0_RC1 NetBSD 4.0_RC1 (BSDUSR2) #1: Mon Sep 3 12:04:19 CEST 2007 dieter@simult.amelgem.be:/build/obj.amd64.4/sys/arch/amd64/compile/BSDUSR2 amd64
Architecture: x86_64
Machine: amd64
>Description:
	systat(1)s refresh interval can be set, but not to a higher
	value than 25 seconds. When a higher number n is typed in,
	it will say 'refresh every n seconds', but instead will
	refresh every 25.5 seconds. This is because the curses
	function timeout(3) is limited to 25500 seconds. I haven't
	tried finding out why this is the case.
>How-To-Repeat:
	systat vmstat 30
	Look at the clock in the upper right corner and see it
	being updated every 25 seconds. Press ^g to see systat lie
	to you.
>Fix:

Following patch divides the wanted interval in chunks of 25 seconds
+ rest and refreshes after all have passed. Since I don't know the
reason for the limit in ncurses, maybe a better fix is to change
it there.

Index: extern.h
===================================================================
RCS file: /cvsroot/src/usr.bin/systat/extern.h,v
retrieving revision 1.37
diff -p -u -r1.37 extern.h
--- extern.h	18 Feb 2007 17:00:08 -0000	1.37
+++ extern.h	9 Sep 2007 19:33:09 -0000
@@ -49,7 +49,7 @@ extern kvm_t	*kd;
 extern long	ntext, textp;
 extern int	CMDLINE;
 extern int	hz, stathz, maxslp;
-extern int	naptime;
+extern int	naptime, napcycles;
 extern int	nhosts;
 extern int	nports;
 extern int	protos;
@@ -153,6 +153,7 @@ void	 labels(void);
 void	 labelswap(void);
 void	 labeltcp(void);
 void	 labeltcpsyn(void);
+void	 nap(void);
 void	 netstat_all(char *);
 void	 netstat_display(char *);
 void	 netstat_ignore(char *);
Index: keyboard.c
===================================================================
RCS file: /cvsroot/src/usr.bin/systat/keyboard.c,v
retrieving revision 1.23
diff -p -u -r1.23 keyboard.c
--- keyboard.c	10 May 2006 21:53:48 -0000	1.23
+++ keyboard.c	9 Sep 2007 19:33:09 -0000
@@ -72,7 +72,10 @@ keyboard(void)
 			refresh();
 			ch = getch();
 			if (ch == ERR) {
-				display(SIGALRM);
+				if (napcycles)
+					nap();
+				else
+					display(SIGALRM);
 				continue;
 			}
 			if (ch == KEY_RESIZE) {
Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/systat/main.c,v
retrieving revision 1.40
diff -p -u -r1.40 main.c
--- main.c	22 Oct 2006 16:43:24 -0000	1.40
+++ main.c	9 Sep 2007 19:33:09 -0000
@@ -75,6 +75,7 @@ sig_t	sigtstpdfl;
 double avenrun[3];
 int     col;
 int	naptime = 5;
+int	napcycles = 0;
 int     verbose = 1;                    /* to report kvm read errs */
 int     hz, stathz, maxslp;
 char    c;
@@ -303,9 +304,21 @@ display(int signo)
 			allcounter=0;
 		} else
 			allcounter++;
-       }
+	}
+
+	nap();
+}
 
-	timeout(naptime * 1000);
+void
+nap(void)
+{
+	if (napcycles) {
+		napcycles--;
+		timeout(25 * 1000);
+	} else {
+		napcycles = naptime / 25;
+		timeout(naptime % 25 * 1000);
+	}
 }
 
 void