CVS commit: src/usr.bin/systat

2024-06-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Jun 16 22:44:01 UTC 2024

Modified Files:
src/usr.bin/systat: main.c

Log Message:
Revert previous, and switch to using real arithmetic.

Ever since this code was first committed to the CSRG SCCS
tree, in Oct 1983, it has contained either
int dellave;
or more recently:
static int dellave;
(that change is irrelevant, as is the move of the declaration
from systat.h into main.c)

And then in main() initialised it as:
dellave = 0.0;

It seems clear to me that the variable really should have been a
double since day one.   All its uses were in floating point contexts.

So, undo the change to use int constants, and instead just make
"dellave" (the load average delta) be a double.

This should make the load average bar which appears at the
top of most systat display screens more sensitive to showing
when the load average is increasing or decreasing (showing
it using '>' or '<' instead of '|' which is used when there
is not much change since last time).


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/systat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/main.c
diff -u src/usr.bin/systat/main.c:1.57 src/usr.bin/systat/main.c:1.58
--- src/usr.bin/systat/main.c:1.57	Fri Jun 14 17:15:45 2024
+++ src/usr.bin/systat/main.c	Sun Jun 16 22:44:01 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.57 2024/06/14 17:15:45 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.58 2024/06/16 22:44:01 kre Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: main.c,v 1.57 2024/06/14 17:15:45 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.58 2024/06/16 22:44:01 kre Exp $");
 #endif /* not lint */
 
 #include 
@@ -59,7 +59,7 @@ __RCSID("$NetBSD: main.c,v 1.57 2024/06/
 #include "extern.h"
 #include "drvstats.h"
 
-static int dellave;
+static double	dellave;
 
 kvm_t *kd;
 char	*memf = NULL;
@@ -237,7 +237,7 @@ main(int argc, char **argv)
 	curmode->c_flags |= CF_INIT;
 	labels();
 
-	dellave = 0;
+	dellave = 0.0;
 
 	display(0);
 	if (!bflag) {
@@ -291,13 +291,13 @@ display(int signo)
 	if (curmode->c_flags & CF_LOADAV) {
 		j = 5.0*avenrun[0] + 0.5;
 		dellave -= avenrun[0];
-		if (dellave >= 0)
+		if (dellave >= 0.0)
 			c = '<';
 		else {
 			c = '>';
 			dellave = -dellave;
 		}
-		if (dellave < 1)
+		if (dellave < 0.1)
 			c = '|';
 		dellave = avenrun[0];
 		wmove(wload, 0, 0);



CVS commit: src/usr.bin/systat

2024-06-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Jun 16 22:44:01 UTC 2024

Modified Files:
src/usr.bin/systat: main.c

Log Message:
Revert previous, and switch to using real arithmetic.

Ever since this code was first committed to the CSRG SCCS
tree, in Oct 1983, it has contained either
int dellave;
or more recently:
static int dellave;
(that change is irrelevant, as is the move of the declaration
from systat.h into main.c)

And then in main() initialised it as:
dellave = 0.0;

It seems clear to me that the variable really should have been a
double since day one.   All its uses were in floating point contexts.

So, undo the change to use int constants, and instead just make
"dellave" (the load average delta) be a double.

This should make the load average bar which appears at the
top of most systat display screens more sensitive to showing
when the load average is increasing or decreasing (showing
it using '>' or '<' instead of '|' which is used when there
is not much change since last time).


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/systat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2024-06-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 14 17:15:45 UTC 2024

Modified Files:
src/usr.bin/systat: main.c

Log Message:
systat: don't compare integer to floating point constants

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/systat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/main.c
diff -u src/usr.bin/systat/main.c:1.56 src/usr.bin/systat/main.c:1.57
--- src/usr.bin/systat/main.c:1.56	Sat Aug 21 13:22:19 2021
+++ src/usr.bin/systat/main.c	Fri Jun 14 17:15:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.56 2021/08/21 13:22:19 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.57 2024/06/14 17:15:45 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: main.c,v 1.56 2021/08/21 13:22:19 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.57 2024/06/14 17:15:45 rillig Exp $");
 #endif /* not lint */
 
 #include 
@@ -237,7 +237,7 @@ main(int argc, char **argv)
 	curmode->c_flags |= CF_INIT;
 	labels();
 
-	dellave = 0.0;
+	dellave = 0;
 
 	display(0);
 	if (!bflag) {
@@ -291,13 +291,13 @@ display(int signo)
 	if (curmode->c_flags & CF_LOADAV) {
 		j = 5.0*avenrun[0] + 0.5;
 		dellave -= avenrun[0];
-		if (dellave >= 0.0)
+		if (dellave >= 0)
 			c = '<';
 		else {
 			c = '>';
 			dellave = -dellave;
 		}
-		if (dellave < 0.1)
+		if (dellave < 1)
 			c = '|';
 		dellave = avenrun[0];
 		wmove(wload, 0, 0);



CVS commit: src/usr.bin/systat

2024-06-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 14 17:15:45 UTC 2024

Modified Files:
src/usr.bin/systat: main.c

Log Message:
systat: don't compare integer to floating point constants

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/systat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2023-03-29 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Mar 29 21:44:35 UTC 2023

Modified Files:
src/usr.bin/systat: systat.1

Log Message:
systat(1): try to give this page a quick facelift

... too bad what it really needs is reconstructive surgery.  I tried
to fix the most obvious problems (unsorted lists, obviously wrong
markup, pleonastic wording that drowns out useful information in
repetition and lifetime supply of quote marks).

This page really needs a native speaker to take some loving care of it.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/systat/systat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2023-03-29 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Mar 29 21:44:35 UTC 2023

Modified Files:
src/usr.bin/systat: systat.1

Log Message:
systat(1): try to give this page a quick facelift

... too bad what it really needs is reconstructive surgery.  I tried
to fix the most obvious problems (unsorted lists, obviously wrong
markup, pleonastic wording that drowns out useful information in
repetition and lifetime supply of quote marks).

This page really needs a native speaker to take some loving care of it.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/systat/systat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/systat.1
diff -u src/usr.bin/systat/systat.1:1.53 src/usr.bin/systat/systat.1:1.54
--- src/usr.bin/systat/systat.1:1.53	Wed Mar 29 19:40:18 2023
+++ src/usr.bin/systat/systat.1	Wed Mar 29 21:44:35 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: systat.1,v 1.53 2023/03/29 19:40:18 kre Exp $
+.\"	$NetBSD: systat.1,v 1.54 2023/03/29 21:44:35 uwe Exp $
 .\"
 .\" Copyright (c) 1985, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)systat.1	8.2 (Berkeley) 12/30/93
 .\"
-.Dd August 21, 2021
+.Dd March 29, 2023
 .Dt SYSTAT 1
 .Os
 .Sh NAME
@@ -43,17 +43,18 @@
 .Op Fl t Ar turns
 .Op Fl w Ar wait
 .Op Ar display
-.Op Ar refresh-interval
+.Op Ar wait
 .Sh DESCRIPTION
 .Nm
 displays various system statistics in a screen oriented fashion
-using the curses screen display library,
-.Xr curses 3 .
+using the
+.Xr curses 3
+screen display library.
 .Pp
 While
 .Nm
-is running the screen is usually divided into two windows (an exception
-is the vmstat display which uses the entire screen).
+is running the screen is usually divided into two windows
+.Pq an exception is the vmstat display which uses the entire screen .
 The upper window depicts the current system load average.
 The information displayed in the lower window may vary, depending on
 user commands.
@@ -65,27 +66,27 @@ displays the processes getting the large
 in the lower window.
 Other displays show more detailed process information,
 swap space usage,
-disk usage statistics (a la
-.Xr df 1 ) ,
-disk I/O statistics (a la
-.Xr iostat 8 ) ,
-virtual memory statistics (a la
-.Xr vmstat 1 ) ,
-network
-.Qq Ic mbufs
-utilization, network
-.Qq Ic ifstat 
-traffic, and network connections (a la
-.Xr netstat 1 ) .
+disk usage statistics
+.Pq a\~la Xr df 1 ,
+disk I/O statistics
+.Pq a\~la Xr iostat 8 ,
+virtual memory statistics
+.Pq a\~la Xr vmstat 1 ,
+network mbuf utilization,
+network interface traffic,
+and network connections
+.Pq a\~la Xr netstat 1 .
 .Pp
 Input is interpreted at two different levels.
-A ``global'' command interpreter processes all keyboard input.
+A global command interpreter processes all keyboard input.
 If this command interpreter fails to recognize a command, the
 input line is passed to a per-display command interpreter.
 This allows each display to have certain display-specific commands.
 .Pp
 Command line options:
-.Bl -tag -width "refresh_interval"
+.Bl -tag -width Fl
+.It Fl b
+Show the chosen display once and exit.
 .It Fl M Ar core
 Extract values associated with the name list from
 .Ar core
@@ -96,22 +97,26 @@ Extract the name list from
 .Ar system
 instead of the default
 .Pa /netbsd .
-.It Fl b
-Show the chosen display once and exit.
 .It Fl n
 Do not resolve IP addresses into string hostnames
-.Pq FQDNs
-on
-.Ic netstat .
+.Pf ( Tn FQDN Ns s ) .
 It has the same effect as
 .Ic numbers
 subcommand in
 .Ic netstat .
-.It Fl w Ar wait
-See
-.Ar refresh-interval .
 .It Fl t Ar turns
-How many refreshes to show each screen in 'all' display mode.
+How many refresh cycles to show each screen in
+.Sq all
+display mode.
+The default is 2.
+.It Fl w Ar wait
+Set the screen refresh interval to
+.Ar wait
+seconds.
+Floating point numbers are accepted.
+The default is 1\~second.
+.It Fl z
+Display 0 instead of space when there is no data.
 .It Ar display
 The
 .Ar display
@@ -136,30 +141,23 @@ or
 .Ic vmstat .
 These displays can also be requested interactively and are described in
 full detail below.
-.It Ar refresh-interval
-The
-.Ar refresh-interval
-specifies the screen refresh time interval in seconds.
-This is provided for backwards compatibility, and overrides the
-.Ar refresh-interval
-specified with the
-.Fl w
-flag.
-.It Fl z
-Display 0 instead of space when there is no data.
+.It Ar wait
+The same as
+.Fl w Ar wait .
+This form is provided for backwards compatibility.
 .El
 .Pp
 Certain characters cause immediate action by
 .Nm  .
 These are
-.Bl -tag -width Fl
+.Bl -tag -width Ic
 .It Ic \&^L
 Refresh the screen.
 .It Ic \&^G
-Print the name of the current ``display'' being shown in
+Print the name of the current display being shown in
 the lower window and the refresh interval.
 .It Ic \&^Z
-Stop
+Suspend
 .Nm  .
 .It 

CVS commit: src/usr.bin/systat

2023-03-29 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 29 19:40:18 UTC 2023

Modified Files:
src/usr.bin/systat: systat.1

Log Message:
PR misc/57305 from Nan Xiao

Be consistent with method (and style) when referring to the mbufs and
ifstat sub-commands when describing what is available (and correct
"mbuf" to be "mbufs" which is what the internal command really is).

That is don't just "double quote" one and 'single quote' the other.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/systat/systat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2023-03-29 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Mar 29 19:40:18 UTC 2023

Modified Files:
src/usr.bin/systat: systat.1

Log Message:
PR misc/57305 from Nan Xiao

Be consistent with method (and style) when referring to the mbufs and
ifstat sub-commands when describing what is available (and correct
"mbuf" to be "mbufs" which is what the internal command really is).

That is don't just "double quote" one and 'single quote' the other.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/systat/systat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/systat.1
diff -u src/usr.bin/systat/systat.1:1.52 src/usr.bin/systat/systat.1:1.53
--- src/usr.bin/systat/systat.1:1.52	Sat Aug 21 13:22:19 2021
+++ src/usr.bin/systat/systat.1	Wed Mar 29 19:40:18 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: systat.1,v 1.52 2021/08/21 13:22:19 christos Exp $
+.\"	$NetBSD: systat.1,v 1.53 2023/03/29 19:40:18 kre Exp $
 .\"
 .\" Copyright (c) 1985, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -71,7 +71,11 @@ disk I/O statistics (a la
 .Xr iostat 8 ) ,
 virtual memory statistics (a la
 .Xr vmstat 1 ) ,
-network ``mbuf'' utilization, network 'ifstat' traffic, and network connections (a la
+network
+.Qq Ic mbufs
+utilization, network
+.Qq Ic ifstat 
+traffic, and network connections (a la
 .Xr netstat 1 ) .
 .Pp
 Input is interpreted at two different levels.



CVS commit: src/usr.bin/systat

2023-03-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Mar 28 00:00:30 UTC 2023

Modified Files:
src/usr.bin/systat: vmstat.c

Log Message:
PR bin/56014 from Kouichi Hashikawa

Don't try to optimise away placing the "s" or " " after "N user"
(" " where N==1, "s" otherwise) when it seems unnecessary, as that
fails when the number of users hasn't changed, but the screen is
being redrawn from nothing (as in after being resumed from a ^Z,
as in the PR, but just doing a ^L would make the same thing happen).

XXX pullup -10 (maybe -9 as well - seems too trivial for -8).


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/systat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/vmstat.c
diff -u src/usr.bin/systat/vmstat.c:1.91 src/usr.bin/systat/vmstat.c:1.92
--- src/usr.bin/systat/vmstat.c:1.91	Tue Nov  9 09:19:01 2021
+++ src/usr.bin/systat/vmstat.c	Tue Mar 28 00:00:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmstat.c,v 1.91 2021/11/09 09:19:01 nia Exp $	*/
+/*	$NetBSD: vmstat.c,v 1.92 2023/03/28 00:00:30 kre Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.91 2021/11/09 09:19:01 nia Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.92 2023/03/28 00:00:30 kre Exp $");
 #endif /* not lint */
 
 /*
@@ -703,19 +703,16 @@ vmstat_zero(char *args)
 static int
 ucount(void)
 {
-	static int onusers = -1;
 	int nusers = 0;
 	struct utmpentry *ehead;
 
 	nusers = getutentries(NULL, );
 
-	if (nusers != onusers) {
-		if (nusers == 1)
-			mvprintw(STATROW, STATCOL + 8, " ");
-		else
-			mvprintw(STATROW, STATCOL + 8, "s");
-	}
-	onusers = nusers;
+	if (nusers == 1)
+		mvprintw(STATROW, STATCOL + 8, " ");
+	else
+		mvprintw(STATROW, STATCOL + 8, "s");
+
 	return (nusers);
 }
 



CVS commit: src/usr.bin/systat

2023-03-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Mar 28 00:00:30 UTC 2023

Modified Files:
src/usr.bin/systat: vmstat.c

Log Message:
PR bin/56014 from Kouichi Hashikawa

Don't try to optimise away placing the "s" or " " after "N user"
(" " where N==1, "s" otherwise) when it seems unnecessary, as that
fails when the number of users hasn't changed, but the screen is
being redrawn from nothing (as in after being resumed from a ^Z,
as in the PR, but just doing a ^L would make the same thing happen).

XXX pullup -10 (maybe -9 as well - seems too trivial for -8).


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/systat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2023-03-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Mar 27 23:20:13 UTC 2023

Modified Files:
src/usr.bin/systat: disks.c

Log Message:
Undo previous "restore lost break" and fix the issue that seems to
have been intending to correct properly (or at least, more rationally).

This makes adding/deleting drives for "vmstat" (and "iostat", though
the man page doesn't say that it also works there) using the :display
:ignore and :drive sub-commands work sensibly using fnmatch()
rather than what was there most of the time since it was added.

Previously ":ignore dk*" would ignore the first dk (wedge) found in
the system (whether or not it was ignored already) and that was it.
[":ignore dk* dk*" would just do that twice.]

Now the same command will ignore all dk* drives (all wedges), which
is what I would anticipate almost anyone would expect it to do.

Similarly for ":display" (to add drives) and ":drives" to explictly
list particular ones.

When the fnmatch() code was added, almost 9 and a half years ago now,
it was almost correct - except always resulted in an error occurring
(though that was little more than a minor inconvenience).

That was "fixed" 5 months later (9 years and almost a month ago now)
with the cvs log message "restore lost break" - which was absolutely
the wrong thing to do (the break was fine when no patterns were used,
and so a name could only ever match one drive - but wrong when the
whole point is to match many).

Somehow in the past 9+ years, no-one noticed that this functionality
had been rendered almost useless.

While here, fix a related problem ... just above I referred to the
error that occurred as a "minor inconvenience" - that's because while
an error would be shown on the screen, it would then immediately be
removed again, an observant user might notice the quick flash, but
that would be it.

Handle that by detecting whether any changes are actually made, and
don't go completely redrawing the screen (removing the error message
that was just placed there) if there is no point.   This doesn't
entirely fix this problem, as if we do

:drives foo wd*

and there is no "foo" drive in the system, we'd get an error message
from that, but adding the wd* drives (assuming there are some, of course)
counts as a change, so that error message will still not last very long.
The order of that command line makes no difference, it isn't that wd drives
were found after foo wasn't, but that the whole line matched (at least one)
drive (and changed its state - for the "drives" command, that is equivalent
to matched) - but also contained an entry which did not match at all.
That's a harder problem to fix.

No pullups planned, as no-one seems to mind how it has been all this time.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/systat/disks.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/disks.c
diff -u src/usr.bin/systat/disks.c:1.19 src/usr.bin/systat/disks.c:1.20
--- src/usr.bin/systat/disks.c:1.19	Sat Mar  8 20:51:20 2014
+++ src/usr.bin/systat/disks.c	Mon Mar 27 23:20:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.19 2014/03/08 20:51:20 jdc Exp $	*/
+/*	$NetBSD: disks.c,v 1.20 2023/03/27 23:20:13 kre Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)disks.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: disks.c,v 1.19 2014/03/08 20:51:20 jdc Exp $");
+__RCSID("$NetBSD: disks.c,v 1.20 2023/03/27 23:20:13 kre Exp $");
 #endif /* not lint */
 
 #include 
@@ -71,6 +71,7 @@ disks_drives(char *args)
 	if (args) {
 		for (i = 0; i < ndrive; i++)
 			drv_select[i] = 0;
+		labels();
 		disks_add(args);
 	} else {
 		move(CMDLINE, 0);
@@ -85,6 +86,8 @@ drvselect(char *args, int truefalse, int
 {
 	char *cp;
 	size_t i;
+	int matched;
+	int changed = 0;
 
 	cp = strchr(args, '\n');
 	if (cp)
@@ -99,15 +102,20 @@ drvselect(char *args, int truefalse, int
 			*cp++ = '\0';
 		if (cp - args == 0)
 			break;
+		matched = 0;
 		for (i = 0; i < ndrive; i++)
 			if (fnmatch(args, dr_name[i], 0) == 0) {
+if (selections[i] != truefalse)
+	changed = 1;
 selections[i] = truefalse;
-break;
+matched = 1;
 			}
-		if (i >= ndrive)
+		if (matched == 0)
 			error("%s: unknown drive", args);
 		args = cp;
 	}
-	labels();
-	display(0);
+	if (changed) {
+		labels();
+		display(0);
+	}
 }



CVS commit: src/usr.bin/systat

2023-03-27 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Mar 27 23:20:13 UTC 2023

Modified Files:
src/usr.bin/systat: disks.c

Log Message:
Undo previous "restore lost break" and fix the issue that seems to
have been intending to correct properly (or at least, more rationally).

This makes adding/deleting drives for "vmstat" (and "iostat", though
the man page doesn't say that it also works there) using the :display
:ignore and :drive sub-commands work sensibly using fnmatch()
rather than what was there most of the time since it was added.

Previously ":ignore dk*" would ignore the first dk (wedge) found in
the system (whether or not it was ignored already) and that was it.
[":ignore dk* dk*" would just do that twice.]

Now the same command will ignore all dk* drives (all wedges), which
is what I would anticipate almost anyone would expect it to do.

Similarly for ":display" (to add drives) and ":drives" to explictly
list particular ones.

When the fnmatch() code was added, almost 9 and a half years ago now,
it was almost correct - except always resulted in an error occurring
(though that was little more than a minor inconvenience).

That was "fixed" 5 months later (9 years and almost a month ago now)
with the cvs log message "restore lost break" - which was absolutely
the wrong thing to do (the break was fine when no patterns were used,
and so a name could only ever match one drive - but wrong when the
whole point is to match many).

Somehow in the past 9+ years, no-one noticed that this functionality
had been rendered almost useless.

While here, fix a related problem ... just above I referred to the
error that occurred as a "minor inconvenience" - that's because while
an error would be shown on the screen, it would then immediately be
removed again, an observant user might notice the quick flash, but
that would be it.

Handle that by detecting whether any changes are actually made, and
don't go completely redrawing the screen (removing the error message
that was just placed there) if there is no point.   This doesn't
entirely fix this problem, as if we do

:drives foo wd*

and there is no "foo" drive in the system, we'd get an error message
from that, but adding the wd* drives (assuming there are some, of course)
counts as a change, so that error message will still not last very long.
The order of that command line makes no difference, it isn't that wd drives
were found after foo wasn't, but that the whole line matched (at least one)
drive (and changed its state - for the "drives" command, that is equivalent
to matched) - but also contained an entry which did not match at all.
That's a harder problem to fix.

No pullups planned, as no-one seems to mind how it has been all this time.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/systat/disks.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2021-11-09 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Nov  9 09:19:02 UTC 2021

Modified Files:
src/usr.bin/systat: vmstat.c

Log Message:
systat(1): convert realloc(x * y) to reallocarr, eliminate a temp var


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/systat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/vmstat.c
diff -u src/usr.bin/systat/vmstat.c:1.90 src/usr.bin/systat/vmstat.c:1.91
--- src/usr.bin/systat/vmstat.c:1.90	Sat Aug 21 13:22:19 2021
+++ src/usr.bin/systat/vmstat.c	Tue Nov  9 09:19:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmstat.c,v 1.90 2021/08/21 13:22:19 christos Exp $	*/
+/*	$NetBSD: vmstat.c,v 1.91 2021/11/09 09:19:01 nia Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.90 2021/08/21 13:22:19 christos Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.91 2021/11/09 09:19:01 nia Exp $");
 #endif /* not lint */
 
 /*
@@ -160,7 +160,6 @@ get_interrupt_events(void)
 	struct evcntlist allevents;
 	struct evcnt evcnt, *evptr;
 	intr_evcnt_t *ie;
-	intr_evcnt_t *n;
 
 	if (!NREAD(X_ALLEVENTS, , sizeof allevents))
 		return;
@@ -170,12 +169,10 @@ get_interrupt_events(void)
 			return;
 		if (evcnt.ev_type != EVCNT_TYPE_INTR)
 			continue;
-		n = realloc(ie_head, sizeof *ie * (nevcnt + 1));
-		if (n == NULL) {
+		if (reallocarr(_head, nevcnt + 1, sizeof(*ie)) != 0) {
 			error("realloc failed");
 			die(0);
 		}
-		ie_head = n;
 		ie = ie_head + nevcnt;
 		ie->ie_group = malloc(evcnt.ev_grouplen + 1);
 		ie->ie_name = malloc(evcnt.ev_namelen + 1);



CVS commit: src/usr.bin/systat

2021-11-09 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Nov  9 09:19:02 UTC 2021

Modified Files:
src/usr.bin/systat: vmstat.c

Log Message:
systat(1): convert realloc(x * y) to reallocarr, eliminate a temp var


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/systat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2021-11-09 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Nov  9 09:18:02 UTC 2021

Modified Files:
src/usr.bin/systat: pigs.c swap.c

Log Message:
systat(1): convert free(x); x = malloc(x * y) to reallocarr.

free on NULL is a guaranteed non-op.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/systat/pigs.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/systat/swap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/pigs.c
diff -u src/usr.bin/systat/pigs.c:1.33 src/usr.bin/systat/pigs.c:1.34
--- src/usr.bin/systat/pigs.c:1.33	Fri Nov 23 03:46:35 2012
+++ src/usr.bin/systat/pigs.c	Tue Nov  9 09:18:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pigs.c,v 1.33 2012/11/23 03:46:35 christos Exp $	*/
+/*	$NetBSD: pigs.c,v 1.34 2021/11/09 09:18:02 nia Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pigs.c	8.2 (Berkeley) 9/23/93";
 #endif
-__RCSID("$NetBSD: pigs.c,v 1.33 2012/11/23 03:46:35 christos Exp $");
+__RCSID("$NetBSD: pigs.c,v 1.34 2021/11/09 09:18:02 nia Exp $");
 #endif /* not lint */
 
 /*
@@ -179,14 +179,11 @@ fetchpigs(void)
 	if ((kpp = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(*kpp),
 )) == NULL) {
 		error("%s", kvm_geterr(kd));
-		if (pt)
-			free(pt);
+		free(pt);
 		return;
 	}
 	if (nproc > lastnproc) {
-		free(pt);
-		if ((pt =
-		malloc((nproc + 1) * sizeof(struct p_times))) == NULL) {
+		if (reallocarr(, nproc + 1, sizeof(struct p_times)) != 0) {
 			error("Out of memory");
 			die(0);
 		}

Index: src/usr.bin/systat/swap.c
diff -u src/usr.bin/systat/swap.c:1.20 src/usr.bin/systat/swap.c:1.21
--- src/usr.bin/systat/swap.c:1.20	Fri May 30 02:29:37 2008
+++ src/usr.bin/systat/swap.c	Tue Nov  9 09:18:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: swap.c,v 1.20 2008/05/30 02:29:37 mrg Exp $	*/
+/*	$NetBSD: swap.c,v 1.21 2021/11/09 09:18:02 nia Exp $	*/
 
 /*
  * Copyright (c) 1997 Matthew R. Green.
@@ -60,7 +60,7 @@
 #if 0
 static char sccsid[] = "@(#)swap.c	8.3 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: swap.c,v 1.20 2008/05/30 02:29:37 mrg Exp $");
+__RCSID("$NetBSD: swap.c,v 1.21 2021/11/09 09:18:02 nia Exp $");
 #endif /* not lint */
 
 #include 
@@ -121,10 +121,8 @@ fetchswap(void)
 		return;
 	update_label = (nswap != rnswap);
 
-	if (swap_devices)
-		(void)free(swap_devices);
-	if ((swap_devices = malloc(nswap * sizeof(*swap_devices))) == NULL) {
-		error("malloc failed");
+	if (reallocarr(_devices, nswap, sizeof(*swap_devices)) != 0) {
+		error("realloc failed");
 		die(0);
 	}
 



CVS commit: src/usr.bin/systat

2021-11-09 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Tue Nov  9 09:18:02 UTC 2021

Modified Files:
src/usr.bin/systat: pigs.c swap.c

Log Message:
systat(1): convert free(x); x = malloc(x * y) to reallocarr.

free on NULL is a guaranteed non-op.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/systat/pigs.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/systat/swap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2021-10-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Oct 30 11:31:51 UTC 2021

Modified Files:
src/usr.bin/systat: netcmds.c

Log Message:
netstat(1): use reallocarr instead of realloc(x * y)


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/systat/netcmds.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/netcmds.c
diff -u src/usr.bin/systat/netcmds.c:1.21 src/usr.bin/systat/netcmds.c:1.22
--- src/usr.bin/systat/netcmds.c:1.21	Sat Feb 26 22:12:33 2005
+++ src/usr.bin/systat/netcmds.c	Sat Oct 30 11:31:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: netcmds.c,v 1.21 2005/02/26 22:12:33 dsl Exp $	*/
+/*	$NetBSD: netcmds.c,v 1.22 2021/10/30 11:31:51 nia Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)netcmds.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: netcmds.c,v 1.21 2005/02/26 22:12:33 dsl Exp $");
+__RCSID("$NetBSD: netcmds.c,v 1.22 2021/10/30 11:31:51 nia Exp $");
 #endif /* not lint */
 
 /*
@@ -223,12 +223,10 @@ selectport(long port, int onoff)
 			p->onoff = onoff;
 			return (0);
 		}
-	p = (struct pitem *)realloc(ports, (nports+1)*sizeof (*p));
-	if (p == NULL) {
+	if (reallocarr(, nports + 1, sizeof(*p)) != 0) {
 		error("malloc failed");
 		die(0);
 	}
-	ports = p;
 	p = [nports++];
 	p->port = port;
 	p->onoff = onoff;
@@ -326,12 +324,10 @@ selecthost(struct sockaddr *sa, int onof
 		}
 	if (sa->sa_len > sizeof(struct sockaddr_storage))
 		return (-1);	/*XXX*/
-	p = (struct hitem *)realloc(hosts, (nhosts+1)*sizeof (*p));
-	if (p == NULL) {
+	if (reallocarr(, nhosts + 1, sizeof(*p)) != 0) {
 		error("malloc failed");
 		die(0);
 	}
-	hosts = p;
 	p = [nhosts++];
 	memcpy(>addr, sa, sa->sa_len);
 	p->onoff = onoff;



CVS commit: src/usr.bin/systat

2021-10-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Oct 30 11:31:51 UTC 2021

Modified Files:
src/usr.bin/systat: netcmds.c

Log Message:
netstat(1): use reallocarr instead of realloc(x * y)


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/systat/netcmds.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2021-08-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 21 13:22:19 UTC 2021

Modified Files:
src/usr.bin/systat: extern.h main.c systat.1 vmstat.c

Log Message:
PR/56331: Paul Goyette: Add -z option to display 0 instead of ' ' in vmstat.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/systat/extern.h
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/systat/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/systat/systat.1
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/systat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/systat

2021-08-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 21 13:22:19 UTC 2021

Modified Files:
src/usr.bin/systat: extern.h main.c systat.1 vmstat.c

Log Message:
PR/56331: Paul Goyette: Add -z option to display 0 instead of ' ' in vmstat.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/systat/extern.h
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/systat/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/systat/systat.1
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/systat/vmstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/systat/extern.h
diff -u src/usr.bin/systat/extern.h:1.47 src/usr.bin/systat/extern.h:1.48
--- src/usr.bin/systat/extern.h:1.47	Fri Jan 25 10:31:11 2019
+++ src/usr.bin/systat/extern.h	Sat Aug 21 09:22:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.47 2019/01/25 15:31:11 christos Exp $	*/
+/*	$NetBSD: extern.h,v 1.48 2021/08/21 13:22:19 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -64,6 +64,7 @@ extern int	turns;
 extern gid_t	egid;
 extern float	hertz;
 extern double	etime;
+extern bool 	showzero;
 
 struct inpcb;
 #ifdef INET6

Index: src/usr.bin/systat/main.c
diff -u src/usr.bin/systat/main.c:1.55 src/usr.bin/systat/main.c:1.56
--- src/usr.bin/systat/main.c:1.55	Fri Jan 25 10:31:11 2019
+++ src/usr.bin/systat/main.c	Sat Aug 21 09:22:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.55 2019/01/25 15:31:11 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.56 2021/08/21 13:22:19 christos Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: main.c,v 1.55 2019/01/25 15:31:11 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.56 2021/08/21 13:22:19 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -81,6 +81,7 @@ int allcounter;
 sig_atomic_t needsredraw = 0;
 float	hertz;
 double	etime;
+bool	showzero = false;
 
 static	WINDOW *wload;			/* one line window for load average */
 
@@ -105,7 +106,7 @@ main(int argc, char **argv)
 	egid = getegid();
 	(void)setegid(getgid());
 
-	while ((ch = getopt(argc, argv, "M:N:bnw:t:")) != -1)
+	while ((ch = getopt(argc, argv, "M:N:bnw:t:z")) != -1)
 		switch(ch) {
 		case 'M':
 			memf = optarg;
@@ -121,11 +122,14 @@ main(int argc, char **argv)
 			break;
 		case 't':
 			if ((turns = atoi(optarg)) <= 0)
-errx(1, "turns <= 0.");
+errx(EXIT_FAILURE, "turns <= 0.");
 			break;
 		case 'w':
 			if ((naptime = strtod(optarg, NULL)) <= 0)
-errx(1, "interval <= 0.");
+errx(EXIT_FAILURE, "interval <= 0.");
+			break;
+		case 'z':
+			showzero = true;
 			break;
 		case '?':
 		default:
@@ -177,7 +181,7 @@ main(int argc, char **argv)
 
 	kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
 	if (kd == NULL)
-		errx(1, "%s", errbuf);
+		errx(EXIT_FAILURE, "%s", errbuf);
 
 	/* Get rid of privs for now. */
 	if (nlistf == NULL && memf == NULL)
@@ -195,7 +199,7 @@ main(int argc, char **argv)
 	 * routines to minimize update work by curses.
 	 */
 	if (initscr() == NULL)
-		errx(1, "couldn't initialize screen");
+		errx(EXIT_FAILURE, "couldn't initialize screen");
 
 	CMDLINE = LINES - 1;
 	wnd = (*curmode->c_open)();
@@ -248,9 +252,9 @@ main(int argc, char **argv)
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: systat [-bn] [-M core] [-N system] [-w wait] "
-		"[-t turns]\n\t\t[display] [refresh-interval]\n");
-	exit(1);
+	fprintf(stderr, "usage: %s [-bnz] [-M core] [-N system] [-w wait] "
+	"[-t turns]\n\t\t[display] [refresh-interval]\n", getprogname());
+	exit(EXIT_FAILURE);
 }
 
 
@@ -366,7 +370,7 @@ die(int signo)
 	clrtoeol();
 	refresh();
 	endwin();
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 
 void
@@ -417,7 +421,7 @@ nlisterr(struct nlist name_list[])
 	clrtoeol();
 	refresh();
 	endwin();
-	exit(1);
+	exit(EXIT_FAILURE);
 }
 
 bool

Index: src/usr.bin/systat/systat.1
diff -u src/usr.bin/systat/systat.1:1.51 src/usr.bin/systat/systat.1:1.52
--- src/usr.bin/systat/systat.1:1.51	Fri Dec 28 07:21:53 2018
+++ src/usr.bin/systat/systat.1	Sat Aug 21 09:22:19 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: systat.1,v 1.51 2018/12/28 12:21:53 wiz Exp $
+.\"	$NetBSD: systat.1,v 1.52 2021/08/21 13:22:19 christos Exp $
 .\"
 .\" Copyright (c) 1985, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)systat.1	8.2 (Berkeley) 12/30/93
 .\"
-.Dd December 26, 2018
+.Dd August 21, 2021
 .Dt SYSTAT 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd display system statistics in a full-screen view
 .Sh SYNOPSIS
 .Nm
-.Op Fl bn
+.Op Fl bnz
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Op Fl t Ar turns
@@ -141,6 +141,8 @@ This is provided for backwards compatibi
 specified with the
 .Fl w
 flag.
+.It Fl z
+Display 0 instead of space when there is no data.
 .El
 .Pp
 Certain characters cause immediate action by

Index: