NetBSD Problem Report #52063

From o.vd.linden@quicknet.nl  Sat Mar 11 12:16:13 2017
Return-Path: <o.vd.linden@quicknet.nl>
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 "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 95F0C7A0F3
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 11 Mar 2017 12:16:13 +0000 (UTC)
Message-Id: <20170311121607.GA13842@sheep>
Date: Sat, 11 Mar 2017 13:16:07 +0100
From: Onno van der Linden <o.vd.linden@quicknet.nl>
To: gnats-bugs@netbsd.org
Subject: halfdelay() does not honour timeout value

>Number:         52063
>Category:       lib
>Synopsis:       timeout value in halfdelay() not honoured
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 11 12:20:00 +0000 2017
>Closed-Date:    Sat Nov 17 21:00:06 +0000 2018
>Last-Modified:  Sat Nov 17 21:00:06 +0000 2018
>Originator:     Onno van der Linden
>Release:        NetBSD 7.99.65
>Organization:

>Environment:
System: NetBSD sheep 7.99.65 NetBSD 7.99.65 (SHEEPKMS) #1: Mon Mar 6 17:11:40 CET 2017 onno@sheep:/sys/arch/i386/compile/SHEEPKMS i386
Architecture: i386
Machine: i386
>Description:
halfdelay() in the curses library has a timeout value in
tenths of seconds that does not seem to be honoured.
pkgsrc/x11/xrestop uses it and it doesn't refresh the
screen with new info but waits for input instead.
>How-To-Repeat:
#include <curses.h>
#include <stdio.h>

main()
{
        int     c;

        initscr();

        halfdelay(20);
        c = wgetch(stdscr);
        fprintf(stderr,"c = %d\n",c);
}

This should quit after 2 seconds and print c = -1.
>Fix:
No idea yet.

>Release-Note:

>Audit-Trail:
From: Onno van der Linden <o.vd.linden@quicknet.nl>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/52063: halfdelay() does not honour timeout value
Date: Sat, 11 Mar 2017 18:00:33 +0100

 Possible fix is to check in __delay() and __nodelay() for
 half_delay mode and return OK. xrestop does work correct now.

 --- /usr/src/lib/libcurses/tty.c.orig	2017-03-11 17:53:02.089562699 +0100
 +++ /usr/src/lib/libcurses/tty.c	2017-03-11 17:54:37.606593383 +0100
 @@ -291,7 +291,8 @@
  	if (_cursesi_screen->endwin)
  		__restartwin();

 -	if (_cursesi_screen->notty == TRUE)
 +	if (_cursesi_screen->notty == TRUE ||
 +	    _cursesi_screen->half_delay == TRUE)
  		return OK;
  	_cursesi_screen->rawt.c_cc[VMIN] = 1;
  	_cursesi_screen->rawt.c_cc[VTIME] = 0;
 @@ -319,7 +320,8 @@
  	if (_cursesi_screen->endwin)
  		__restartwin();

 -	if (_cursesi_screen->notty == TRUE)
 +	if (_cursesi_screen->notty == TRUE ||
 +	    _cursesi_screen->half_delay == TRUE)
  		return OK;
  	_cursesi_screen->rawt.c_cc[VMIN] = 0;
  	_cursesi_screen->rawt.c_cc[VTIME] = 0;

From: Onno van der Linden <o.vd.linden@quicknet.nl>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/52063: halfdelay() does not honour timeout value
Date: Tue, 7 Aug 2018 21:51:21 +0200

 After Brett Lymn told me he wasn't comfortable with the patch I tried
 to come up with something better. Noticed a difference between
 wgetch() and wget_wch() in handling win->delay. Made that handling
 in wgetch() equal to wget_wch():

 $ diff -u `pwd`/getch.c.orig `pwd`/getch.c
 --- /usr/src/lib/libcurses/getch.c.orig 2017-01-31 10:17:53.000000000 +0100
 +++ /usr/src/lib/libcurses/getch.c      2018-08-07 21:33:41.361102323 +0200
 @@ -867,8 +867,6 @@
                 switch (win->delay)
                 {
                 case -1:
 -                       if (__delay() == ERR)
 -                               return ERR;
                         break;
                 case 0:
                         if (__nodelay() == ERR)


 And now the testscript works fine.

 Onno

From: Brett Lymn <blymn@internode.on.net>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,
        Onno van der Linden <o.vd.linden@quicknet.nl>
Subject: Re: lib/52063: halfdelay() does not honour timeout value
Date: Wed, 8 Aug 2018 08:02:33 +0930

 On Tue, Aug 07, 2018 at 07:55:01PM +0000, Onno van der Linden wrote:
 > 
 >  After Brett Lymn told me he wasn't comfortable with the patch I tried
 >  to come up with something better. Noticed a difference between
 >  wgetch() and wget_wch() in handling win->delay. Made that handling
 >  in wgetch() equal to wget_wch():
 >  
 >  $ diff -u `pwd`/getch.c.orig `pwd`/getch.c
 >  --- /usr/src/lib/libcurses/getch.c.orig 2017-01-31 10:17:53.000000000 +0100
 >  +++ /usr/src/lib/libcurses/getch.c      2018-08-07 21:33:41.361102323 +0200
 >  @@ -867,8 +867,6 @@
 >                  switch (win->delay)
 >                  {
 >                  case -1:
 >  -                       if (__delay() == ERR)
 >  -                               return ERR;
 >                          break;
 >                  case 0:
 >                          if (__nodelay() == ERR)
 >  
 >  
 >  And now the testscript works fine.
 >  

 Sorry Onno, I know that would work but looking at it this bug goes a bit
 deeper.  I think that what both wgetch and wget_wch are doing is
 incorrect.  Looking at SUSv2, it says that halfdelay should apply to the
 current window.  Our curses is, as Simon pointed out, applying the
 setting to the screen.  I think what we need to do is fix halfdelay so
 it applies to the window and fix both wgetch and wget_wch so they
 correctly set halfdelay for the window.

 This will fix your bug and make our curses correct as per SUSv2.

 -- 
 Brett Lymn
 Let go, or be dragged - Zen proverb.

State-Changed-From-To: open->feedback
State-Changed-By: blymn@NetBSD.org
State-Changed-When: Fri, 16 Nov 2018 10:14:00 +0000
State-Changed-Why:
Committed an improved version of the suggested fix provided by Onno.


From: "Brett Lymn" <blymn@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52063 CVS commit: src/lib/libcurses
Date: Fri, 16 Nov 2018 10:12:00 +0000

 Module Name:	src
 Committed By:	blymn
 Date:		Fri Nov 16 10:12:00 UTC 2018

 Modified Files:
 	src/lib/libcurses: curses_private.h fileio.h screen.c shlib_version
 	    tty.c

 Log Message:
 Fix for PR lib/52063
 Many thanks to  Onno van der Linden (o.vd.linden@quicknet.nl) for providing
 the bulk of the patch that fixes the issue.


 To generate a diff of this commit:
 cvs rdiff -u -r1.67 -r1.68 src/lib/libcurses/curses_private.h
 cvs rdiff -u -r1.4 -r1.5 src/lib/libcurses/fileio.h
 cvs rdiff -u -r1.34 -r1.35 src/lib/libcurses/screen.c
 cvs rdiff -u -r1.42 -r1.43 src/lib/libcurses/shlib_version
 cvs rdiff -u -r1.47 -r1.48 src/lib/libcurses/tty.c

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

State-Changed-From-To: feedback->closed
State-Changed-By: blymn@NetBSD.org
State-Changed-When: Sat, 17 Nov 2018 21:00:06 +0000
State-Changed-Why:
Confirmed fixed by reporter.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.