NetBSD Problem Report #53906

From stix@stix.id.au  Fri Jan 25 06:35:00 2019
Return-Path: <stix@stix.id.au>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id E2BE37A111
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 25 Jan 2019 06:35:00 +0000 (UTC)
Message-Id: <20190125063452.A2ECE19E5C@stix.id.au>
Date: Fri, 25 Jan 2019 17:34:52 +1100 (AEDT)
From: stix@stix.id.au
Reply-To: stixpjr@gmail.com
To: gnats-bugs@NetBSD.org
Subject: systat(1) vmstat & syscall get "alternate system clock has died" on terminal resize (SIGWINCH)
X-Send-Pr-Version: 3.95

>Number:         53906
>Category:       bin
>Synopsis:       systat(1) vmstat & syscall get "alternate system clock has died" on terminal resize (SIGWINCH)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 25 06:35:01 +0000 2019
>Closed-Date:    Mon Mar 27 23:46:11 +0000 2023
>Last-Modified:  Mon Mar 27 23:46:11 +0000 2023
>Originator:     Paul Ripke
>Release:        NetBSD 8.0_STABLE
>Organization:
Paul Ripke
"Great minds discuss ideas, average minds discuss events, small minds
 discuss people."
-- Disputed: Often attributed to Eleanor Roosevelt. 1948.
>Environment:
System: NetBSD slave 8.0_STABLE NetBSD 8.0_STABLE (SLAVE) #2: Mon Nov 5 16:27:42 AEDT 2018 stix@slave:/home/netbsd/netbsd-8/obj.amd64/home/netbsd/netbsd-8/src/sys/arch/amd64/compile/SLAVE amd64
Architecture: x86_64
Machine: amd64
>Description:
	When running systat with vmstat or syscall view, a terminal resize generates the "alternate system clock has died" and reverts to the pigs display, spins using a full core, and fails to respond to keys.
>How-To-Repeat:
	Start "systat vm" in an xterm, and resize the xterm.
>Fix:
	The fix for pr/53636 may have been the trigger, but the code is still broken as-is. The below patch fixes it for me - I opted to leave the "alternate system clock has died" code in, although it likely should be killed off. Crucially, we can't, and should not, call resizeterm(3) in redraw(), since this results in us receiving an endless stream of KEY_RESIZE events.

diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c
index 3325d5f147bc..df0ffeb45ae3 100644
--- a/usr.bin/systat/main.c
+++ b/usr.bin/systat/main.c
@@ -332,7 +332,6 @@ display(int signo)
 void
 redraw(void)
 {
-	resizeterm(LINES, COLS);
 	CMDLINE = LINES - 1;
 	labels();

diff --git a/usr.bin/systat/syscall.c b/usr.bin/systat/syscall.c
index c943af2b11ae..1d27524ab044 100644
--- a/usr.bin/systat/syscall.c
+++ b/usr.bin/systat/syscall.c
@@ -43,6 +43,7 @@ __RCSID("$NetBSD: syscall.c,v 1.9 2014/02/19 20:42:14 dsl Exp $");
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <util.h>

 #include "systat.h"
@@ -197,10 +198,15 @@ showsyscall(void)
 	cpuswap();
 	if (display_mode == TIME) {
 		etime = cur.cp_etime;
-		/* < 5 ticks - ignore this trash */
+		/* < 1 ticks - sleep for a tick */
+		/* this is often triggered by repeated SIGWINCH */
 		if ((etime * hertz) < 1.0) {
-			if (failcnt++ <= MAXFAIL)
+			if (failcnt++ <= MAXFAIL) {
+				struct timespec interval = { 0, 1000000000L / hertz };
+				while (nanosleep(&interval, &interval) != 0)
+					;
 				return;
+			}
 			clear();
 			mvprintw(2, 10, "The alternate system clock has died!");
 			mvprintw(3, 10, "Reverting to ``pigs'' display.");
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c
index 526ee07f1304..ed92a34903ec 100644
--- a/usr.bin/systat/vmstat.c
+++ b/usr.bin/systat/vmstat.c
@@ -52,6 +52,7 @@ __RCSID("$NetBSD: vmstat.c,v 1.84 2019/01/08 08:22:20 tih Exp $");
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <util.h>

 #include "systat.h"
@@ -499,10 +500,15 @@ showvmstat(void)
 	if (display_mode == TIME) {
 		drvswap();
 		etime = cur.cp_etime;
-		/* < 5 ticks - ignore this trash */
+		/* < 1 ticks - sleep for a tick */
+		/* this is often triggered by repeated SIGWINCH */
 		if ((etime * hertz) < 1.0) {
-			if (failcnt++ <= MAXFAIL)
+			if (failcnt++ <= MAXFAIL) {
+				struct timespec interval = { 0, 1000000000L / hertz };
+				while (nanosleep(&interval, &interval) != 0)
+					;
 				return;
+			}
 			clear();
 			mvprintw(2, 10, "The alternate system clock has died!");
 			mvprintw(3, 10, "Reverting to ``pigs'' display.");

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53906 CVS commit: src/usr.bin/systat
Date: Fri, 25 Jan 2019 10:31:11 -0500

 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.

From: Paul Ripke <stixpjr@gmail.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: PR/53906 CVS commit: src/usr.bin/systat
Date: Tue, 29 Jan 2019 00:37:45 +1100

 --000000000000d3667e058084c861
 Content-Type: text/plain; charset="UTF-8"

 Thanks, Christos!

 Any chance of a pull-up to netbsd-8?

 --000000000000d3667e058084c861
 Content-Type: text/html; charset="UTF-8"

 <div dir="ltr">Thanks, Christos!<br><br>Any chance of a pull-up to netbsd-8?</div>

 --000000000000d3667e058084c861--

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, 
	stixpjr@gmail.com
Cc: 
Subject: Re: PR/53906 CVS commit: src/usr.bin/systat
Date: Mon, 28 Jan 2019 08:44:42 -0500

 On Jan 28,  1:40pm, stixpjr@gmail.com (Paul Ripke) wrote:
 -- Subject: Re: PR/53906 CVS commit: src/usr.bin/systat

 |  Thanks, Christos!
 |  
 |  Any chance of a pull-up to netbsd-8?

 Sure, let me gather the changes.

 christos

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53906 CVS commit: [netbsd-8] src/usr.bin/systat
Date: Wed, 30 Jan 2019 13:46:26 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Wed Jan 30 13:46:25 UTC 2019

 Modified Files:
 	src/usr.bin/systat [netbsd-8]: extern.h iostat.c main.c syscall.c
 	    vmstat.c

 Log Message:
 Pull up following revision(s) (requested by christos in ticket #1176):

 	usr.bin/systat/main.c: revision 1.55
 	usr.bin/systat/extern.h: revision 1.47
 	usr.bin/systat/syscall.c: revision 1.10
 	usr.bin/systat/iostat.c: revision 1.39
 	usr.bin/systat/vmstat.c: revision 1.85
 	usr.bin/systat/vmstat.c: revision 1.86

 no need for curses.h

  -

 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.46.6.1 src/usr.bin/systat/extern.h
 cvs rdiff -u -r1.37.38.1 -r1.37.38.2 src/usr.bin/systat/iostat.c
 cvs rdiff -u -r1.51 -r1.51.6.1 src/usr.bin/systat/main.c
 cvs rdiff -u -r1.9 -r1.9.18.1 src/usr.bin/systat/syscall.c
 cvs rdiff -u -r1.81.8.1 -r1.81.8.2 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.

State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Mon, 27 Mar 2023 23:46:11 +0000
State-Changed-Why:
Fixed in Jan 2019, pulled up (to -8).


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.