On Mon, Jan 13, 2014 at 05:04:28PM +0000, Stuart Henderson wrote:
> If anyone is interested in looking at a signal problem in top,
> here's a small but annoying bug..
>
> - run top in an xterm
> - resize the window
> - try to use an interactive command that takes an argument, e.g. "s"
> or "g" (doesn't happen with commands like "S" or "H" that work immediately)
>
> Often, pressing the command key just refreshes the screen, it takes
> multiple attempts for the command to take effect (sometimes just a
> couple, sometimes loads of attempts).
> [...]
The patch below seems to fix that for me. resizeterm() does a
putchar(KEY_RESIZE), part of which then gets interpreted as a command parameter
in rundisplay().
I'm not too sure on the cast to char, but since isascii() makes sure the
value passed is below 0177, i figured that would be okay.
--
Gregor Best
--- top.c.old Mon Jan 13 20:49:28 2014
+++ top.c Mon Jan 13 20:49:11 2014
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
+#include <ctype.h>
/* includes specific to top */
#include "display.h" /* interface to display package */
@@ -548,7 +549,7 @@
static char tempbuf[TEMPBUFSIZE];
sigset_t mask;
char ch, *iptr;
- int change, i;
+ int change, i, cch;
struct pollfd pfd[1];
uid_t uid, huid;
static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P1";
@@ -612,14 +613,12 @@
* now read it and convert to
* command strchr
*/
- while (1) {
- len = read(STDIN_FILENO, &ch, 1);
- if (len == -1 && errno == EINTR)
- continue;
- if (len == 0)
- exit(1);
- break;
- }
+ cch = getch();
+ /* If the terminal is resized, curses does putchar(KEY_RESIZE)
*/
+ if (!isascii(cch))
+ return 0;
+ ch = (char) cch;
+
if ((iptr = strchr(command_chars, ch)) == NULL) {
/* illegal command */
new_message(MT_standout, " Command not understood");