NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/53615: curses(3) KEY_RESIZE does not work



The following reply was made to PR lib/53615; it has been noted by GNATS.

From: Rin Okuyama <rokuyama%rk.phys.keio.ac.jp@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: lib/53615: curses(3) KEY_RESIZE does not work
Date: Wed, 19 Sep 2018 00:32:40 +0900

 This is because it does not check whether windows is resized or not
 when fgetc() fails with EINTR. This regression was introduced in
 getch.c r1.50:
 
 http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libcurses/getch.c#rev1.50
 
 This patch fixes your problem, and I hope that it breaks nothing...
 
 ----
 Index: lib/libcurses/get_wch.c
 ===================================================================
 RCS file: /home/netbsd/src/lib/libcurses/get_wch.c,v
 retrieving revision 1.14
 diff -p -u -r1.14 get_wch.c
 --- lib/libcurses/get_wch.c	31 Jan 2017 09:17:53 -0000	1.14
 +++ lib/libcurses/get_wch.c	18 Sep 2018 14:35:59 -0000
 @@ -39,6 +39,7 @@
   __RCSID("$NetBSD: get_wch.c,v 1.14 2017/01/31 09:17:53 roy Exp $");
   #endif						  /* not lint */
   
 +#include <errno.h>
   #include <string.h>
   #include <stdlib.h>
   #include <unistd.h>
 @@ -596,7 +597,11 @@ wget_wch(WINDOW *win, wint_t *ch)
   
   		if (ferror(infd)) {
   			clearerr(infd);
 -			return ERR;
 +			if (errno == EINTR && _cursesi_screen->resized) {
 +				*ch = KEY_RESIZE;
 +				return KEY_CODE_YES;
 +			} else
 +				return ERR;
   		} else {
   			ret = c;
   			inp = c;
 Index: lib/libcurses/getch.c
 ===================================================================
 RCS file: /home/netbsd/src/lib/libcurses/getch.c,v
 retrieving revision 1.65
 diff -p -u -r1.65 getch.c
 --- lib/libcurses/getch.c	31 Jan 2017 09:17:53 -0000	1.65
 +++ lib/libcurses/getch.c	18 Sep 2018 14:31:28 -0000
 @@ -38,6 +38,7 @@ __RCSID("$NetBSD: getch.c,v 1.65 2017/01
   #endif
   #endif					/* not lint */
   
 +#include <errno.h>
   #include <string.h>
   #include <stdlib.h>
   #include <unistd.h>
 @@ -889,7 +890,11 @@ wgetch(WINDOW *win)
   
   		if (ferror(infd)) {
   			clearerr(infd);
 -			inp = ERR;
 +			if (errno == EINTR && _cursesi_screen->resized) {
 +				_cursesi_screen->resized = 0;
 +				inp = KEY_RESIZE;
 +			} else
 +				inp = ERR;
   		} else {
   			inp = c;
   		}
 ----
 
 For SIGWINCH handler, I found inappropriate NULL check for sa_handler.
 It should be compared to all of SIG_* in <sys/signal.h>, as in a
 similar manner to jmcneill's fix for nvi:
 
 http://cvsweb.netbsd.org/bsdweb.cgi/src/external/bsd/nvi/dist/cl/cl_main.c#rev1.9
 
 Also, I don't understand why _cursei_screen->resized is not updated
 when a previous handler exists. How do you think of this patch?
 
 ----
 Index: lib/libcurses/tstp.c
 ===================================================================
 RCS file: /home/netbsd/src/lib/libcurses/tstp.c,v
 retrieving revision 1.42
 diff -p -u -r1.42 tstp.c
 --- lib/libcurses/tstp.c	6 Jan 2017 13:53:18 -0000	1.42
 +++ lib/libcurses/tstp.c	18 Sep 2018 15:19:16 -0000
 @@ -148,12 +148,15 @@ __winch_signal_handler(/*ARGSUSED*/int s
   	}
   	/*
   	 * If there was a previous handler, call that,
 -	 * otherwise tell getch() to send KEY_RESIZE.
 +	 * then tell getch() to send KEY_RESIZE.
   	 */
 -	if (owsa.sa_handler !=  NULL)
 +	if (owsa.sa_handler != SIG_DFL &&
 +	    owsa.sa_handler != SIG_IGN &&
 +	    owsa.sa_handler != SIG_ERR &&
 +	    owsa.sa_handler != SIG_HOLD)
   		owsa.sa_handler(signo);
 -	else
 -		_cursesi_screen->resized = 1;
 +
 +	_cursesi_screen->resized = 1;
   }
   
   /*
 ----
 
 Thanks
 rin
 


Home | Main Index | Thread Index | Old Index