Module Name:    src
Committed By:   christos
Date:           Fri Jan 25 15:31:11 UTC 2019

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

Log Message:
PR/53906: Paul Ripke: systat(1) vmstat & syscall get
"alternate system clock has died" on terminal resize (SIGWINCH)


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/systat/extern.h
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/systat/iostat.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/systat/main.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/systat/syscall.c
cvs rdiff -u -r1.84 -r1.85 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.46 src/usr.bin/systat/extern.h:1.47
--- src/usr.bin/systat/extern.h:1.46	Sat Oct 22 18:02:55 2016
+++ src/usr.bin/systat/extern.h	Fri Jan 25 10:31:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.46 2016/10/22 22:02:55 christos Exp $	*/
+/*	$NetBSD: extern.h,v 1.47 2019/01/25 15:31:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -33,10 +33,12 @@
 
 #include <sys/cdefs.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <kvm.h>
 
 #define ADJINETCTR(c, o, n, e)	(c.e = n.e - o.e)
 #define xADJINETCTR(c, o, n, e)	(c[e] = n[e] - o[e])
+#define MAXFAIL	5
 
 extern struct	command global_commands[];
 extern struct	mode *curmode;
@@ -60,6 +62,8 @@ extern char	*memf;
 extern int	allflag;
 extern int	turns;
 extern gid_t	egid;
+extern float	hertz;
+extern double	etime;
 
 struct inpcb;
 #ifdef INET6
@@ -210,6 +214,7 @@ void	 tcp_boot(char *);
 void	 tcp_run(char *);
 void	 tcp_time(char *);
 void	 tcp_zero(char *);
+bool	 toofast(int *);
 void	 vmstat_boot(char *);
 void	 vmstat_run(char *);
 void	 vmstat_time(char *);

Index: src/usr.bin/systat/iostat.c
diff -u src/usr.bin/systat/iostat.c:1.38 src/usr.bin/systat/iostat.c:1.39
--- src/usr.bin/systat/iostat.c:1.38	Sat Jul 15 04:22:23 2017
+++ src/usr.bin/systat/iostat.c	Fri Jan 25 10:31:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: iostat.c,v 1.38 2017/07/15 08:22:23 mlelstv Exp $	*/
+/*	$NetBSD: iostat.c,v 1.39 2019/01/25 15:31:11 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)iostat.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: iostat.c,v 1.38 2017/07/15 08:22:23 mlelstv Exp $");
+__RCSID("$NetBSD: iostat.c,v 1.39 2019/01/25 15:31:11 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -46,7 +46,6 @@ __RCSID("$NetBSD: iostat.c,v 1.38 2017/0
 #include "drvstats.h"
 
 static  int linesperregion;
-static	double etime;
 static  int numbers = 0;		/* default display bar graphs */
 static  int secs = 0;			/* default seconds shown */
 static  int read_write = 0;		/* default read/write shown */

Index: src/usr.bin/systat/main.c
diff -u src/usr.bin/systat/main.c:1.54 src/usr.bin/systat/main.c:1.55
--- src/usr.bin/systat/main.c:1.54	Tue Dec 25 20:47:37 2018
+++ src/usr.bin/systat/main.c	Fri Jan 25 10:31:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.54 2018/12/26 01:47:37 sevan Exp $	*/
+/*	$NetBSD: main.c,v 1.55 2019/01/25 15:31:11 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.54 2018/12/26 01:47:37 sevan Exp $");
+__RCSID("$NetBSD: main.c,v 1.55 2019/01/25 15:31:11 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -57,6 +57,7 @@ __RCSID("$NetBSD: main.c,v 1.54 2018/12/
 
 #include "systat.h"
 #include "extern.h"
+#include "drvstats.h"
 
 static int     dellave;
 
@@ -78,6 +79,8 @@ int     turns = 2;	/* stay how many refr
 int     allflag;
 int     allcounter;
 sig_atomic_t needsredraw = 0;
+float	hertz;
+double	etime;
 
 static	WINDOW *wload;			/* one line window for load average */
 
@@ -332,7 +335,6 @@ display(int signo)
 void
 redraw(void)
 {
-	resizeterm(LINES, COLS);
 	CMDLINE = LINES - 1;
 	labels();
 
@@ -417,3 +419,30 @@ nlisterr(struct nlist name_list[])
 	endwin();
 	exit(1);
 }
+
+bool
+toofast(int *failcnt)
+{
+	static char pigs[] = "pigs";
+	etime = cur.cp_etime;
+	/* < 1 ticks - sleep for a tick */
+	/* this is often triggered by repeated SIGWINCH */
+	if ((etime * hertz) >= 1.0)
+		return false;
+
+	if ((*failcnt)++ <= MAXFAIL) {
+		struct timespec interval = { 0, 1000000000L / hertz };
+		while (nanosleep(&interval, &interval) == -1)
+			continue;
+		return true;
+	}
+	clear();
+	mvprintw(2, 10, "The alternate system clock has died!");
+	mvprintw(3, 10, "Reverting to ``pigs'' display.");
+	move(CMDLINE, 0);
+	refresh();
+	failcnt = 0;
+	sleep(5);
+	command(pigs);
+	return true;
+}

Index: src/usr.bin/systat/syscall.c
diff -u src/usr.bin/systat/syscall.c:1.9 src/usr.bin/systat/syscall.c:1.10
--- src/usr.bin/systat/syscall.c:1.9	Wed Feb 19 15:42:14 2014
+++ src/usr.bin/systat/syscall.c	Fri Jan 25 10:31:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: syscall.c,v 1.9 2014/02/19 20:42:14 dsl Exp $	*/
+/*	$NetBSD: syscall.c,v 1.10 2019/01/25 15:31:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: syscall.c,v 1.9 2014/02/19 20:42:14 dsl Exp $");
+__RCSID("$NetBSD: syscall.c,v 1.10 2019/01/25 15:31:11 christos Exp $");
 
 /* System call stats */
 
@@ -75,7 +75,6 @@ static int show = SHOW_COUNTS;
 static void getinfo(struct Info *, int);
 
 static	char buf[32];
-static	float hertz;
 
 static size_t counts_mib_len, times_mib_len;
 static int counts_mib[4], times_mib[4];
@@ -146,8 +145,6 @@ labelsyscall(void)
 	labelvmstat_top();
 }
 
-#define MAXFAIL 5
-
 static void
 putuint64(uint64_t v, int row, int col, int width)
 {
@@ -186,7 +183,6 @@ showsyscall(void)
 	uint64_t v;
 	static int failcnt = 0;
 	static int relabel = 0;
-	static char pigs[] = "pigs";
 	uint64_t itime;
 
 	if (relabel) {
@@ -196,21 +192,8 @@ showsyscall(void)
 
 	cpuswap();
 	if (display_mode == TIME) {
-		etime = cur.cp_etime;
-		/* < 5 ticks - ignore this trash */
-		if ((etime * hertz) < 1.0) {
-			if (failcnt++ <= MAXFAIL)
-				return;
-			clear();
-			mvprintw(2, 10, "The alternate system clock has died!");
-			mvprintw(3, 10, "Reverting to ``pigs'' display.");
-			move(CMDLINE, 0);
-			refresh();
-			failcnt = 0;
-			sleep(5);
-			command(pigs);
+		if (toofast(&failcnt))
 			return;
-		}
 	} else
 		etime = 1.0;
 	itime = etime * 100;

Index: src/usr.bin/systat/vmstat.c
diff -u src/usr.bin/systat/vmstat.c:1.84 src/usr.bin/systat/vmstat.c:1.85
--- src/usr.bin/systat/vmstat.c:1.84	Tue Jan  8 03:22:20 2019
+++ src/usr.bin/systat/vmstat.c	Fri Jan 25 10:31:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmstat.c,v 1.84 2019/01/08 08:22:20 tih Exp $	*/
+/*	$NetBSD: vmstat.c,v 1.85 2019/01/25 15:31:11 christos 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.84 2019/01/08 08:22:20 tih Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.85 2019/01/25 15:31:11 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -53,6 +53,7 @@ __RCSID("$NetBSD: vmstat.c,v 1.84 2019/0
 #include <stdlib.h>
 #include <string.h>
 #include <util.h>
+#include <curses.h>
 
 #include "systat.h"
 #include "extern.h"
@@ -80,8 +81,6 @@ static int ucount(void);
 
 static	char buf[26];
 static	u_int64_t temp;
-double etime;
-static	float hertz;
 static	int nintr;
 static	long *intrloc;
 static	char **intrname;
@@ -415,7 +414,6 @@ labelvmstat(void)
 			{temp = (s).fld; (s).fld -= (s1).fld; \
 			if (display_mode == TIME) (s1).fld = temp; \
 			putint((int)((float)(s).fld/etime + 0.5), l, c, w);}
-#define MAXFAIL 5
 
 static	char cpuchar[CPUSTATES] = { '=' , '>', '-', '%', ' ' };
 static	char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_INTR, CP_IDLE };
@@ -483,7 +481,6 @@ showvmstat(void)
 	static int failcnt = 0;
 	static int relabel = 0;
 	static int last_disks = 0;
-	static char pigs[] = "pigs";
 	static u_long bufmem;
 	struct buf_sysctl *buffers;
 	int mib[6];
@@ -498,21 +495,8 @@ showvmstat(void)
 	cpuswap();
 	if (display_mode == TIME) {
 		drvswap();
-		etime = cur.cp_etime;
-		/* < 5 ticks - ignore this trash */
-		if ((etime * hertz) < 1.0) {
-			if (failcnt++ <= MAXFAIL)
-				return;
-			clear();
-			mvprintw(2, 10, "The alternate system clock has died!");
-			mvprintw(3, 10, "Reverting to ``pigs'' display.");
-			move(CMDLINE, 0);
-			refresh();
-			failcnt = 0;
-			sleep(5);
-			command(pigs);
+		if (toofast(&failcnt))
 			return;
-		}
 	} else
 		etime = 1.0;
 

Reply via email to