From fjoe@iclub.nsu.ru Fri Sep 10 06:35:25 1999
Return-Path: <fjoe@iclub.nsu.ru>
Received: from iclub.nsu.ru (iclub.nsu.ru [193.124.222.66])
	by hub.freebsd.org (Postfix) with ESMTP id B94D8153FB
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 10 Sep 1999 06:34:55 -0700 (PDT)
	(envelope-from fjoe@iclub.nsu.ru)
Received: (from fjoe@localhost)
	by iclub.nsu.ru (8.9.3/8.9.3) id UAA27832;
	Fri, 10 Sep 1999 20:33:44 +0700 (NSS)
	(envelope-from fjoe)
Message-Id: <199909101333.UAA27832@iclub.nsu.ru>
Date: Fri, 10 Sep 1999 20:33:44 +0700 (NSS)
From: Max Khon <fjoe@iclub.nsu.ru>
Reply-To: fjoe@iclub.nsu.ru
To: FreeBSD-gnats-submit@freebsd.org
Subject: ncurses-based programs eat 100% CPU after telnet session is ungracefully closed<Synopsis of the problem (one line)>
X-Send-Pr-Version: 3.2

>Number:         13679
>Category:       bin
>Synopsis:       ncurses-based programs eat 100% CPU after telnet session is ungracefully closed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    mikeh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 10 06:40:02 PDT 1999
>Closed-Date:    Sun Jun 17 16:11:31 PDT 2001
>Last-Modified:  Sun Jun 17 16:11:56 PDT 2001
>Originator:     Max Khon
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
WebSci Technologies Inc.
>Environment:

	FreeBSD 3.2-STABLE (last cvsup 3 Sep 1998)
	(any -stable version)

>Description:

	ncurses-based programs (ee, midc, pdmenu) hang with 100% CPU usage when
	telnet (ssh, whatever) connection is closed ungracefully.

>How-To-Repeat:

	open telnet session to some host
	run 'ee'
	press ^[
	enter 'close'
	open telnet session again and check 'top' output. you will see
	'ee' at the top eating all the available CPU time.
	

>Fix:
	
	apply this fix against /usr/src/lib/libncurses

*** lib_getch.c.orig	Fri Sep 10 19:36:10 1999
--- lib_getch.c	Fri Sep 10 19:58:09 1999
*************** unsigned char ch;
*** 77,82 ****
--- 77,84 ----
  	if (tail == -1) return ERR;
  again:
  	n = read(fileno(SP->_ifp), &ch, 1);
+ 	if (!n)
+ 		return ERR;			/* EOF */
  	if (n == -1 && errno == EINTR)
  		goto again;
  	T(("read %d characters", n));
*************** int	ch;
*** 140,147 ****
  	if (win->_use_keypad)
  		ch = kgetch(win);
  	else {
! 		if (head == -1)
! 			fifo_push();
  		ch = fifo_pull();
  	}
  
--- 142,151 ----
  	if (win->_use_keypad)
  		ch = kgetch(win);
  	else {
! 		if (head == -1) {
! 			if (fifo_push() == ERR)
! 				return ERR;
! 		} 
  		ch = fifo_pull();
  	}
  
*************** int timeleft = 1000;
*** 192,197 ****
--- 196,203 ----
  
  	if (head == -1)  {
  		ch = fifo_push();
+ 		if (ch == ERR)
+ 			return ch;
  		peek = 0;
      	while (ptr != NULL) {
  			T(("ch = %d", ch));
*************** int timeleft = 1000;
*** 215,221 ****
  				return(fifo_pull());
     			} else {
     				T(("got more!"));
!    				fifo_push();
     				ch = fifo_peek();
     			}
  		}
--- 221,228 ----
  				return(fifo_pull());
     			} else {
     				T(("got more!"));
!    				if (fifo_push() == ERR)
! 					return ERR;
     				ch = fifo_peek();
     			}
  		}

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: steve 
Responsible-Changed-When: Sun Sep 12 14:10:36 PDT 1999 
Responsible-Changed-Why:  
Misfiled PR. 
State-Changed-From-To: open->feedback 
State-Changed-By: mikeh 
State-Changed-When: Sun Jun 17 00:47:39 PDT 2001 
State-Changed-Why:  
Is this still a problem with latest ncurses? 


Responsible-Changed-From-To: freebsd-bugs->mikeh 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Sun Jun 17 00:47:39 PDT 2001 
Responsible-Changed-Why:  
I'll handle feedback. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=13679 
State-Changed-From-To: feedback->closed 
State-Changed-By: mikeh 
State-Changed-When: Sun Jun 17 16:11:31 PDT 2001 
State-Changed-Why:  
Submitter reports problem is fixed. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=13679 
>Unformatted:
