aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--procps/top.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/procps/top.c b/procps/top.c
index 89e5d5f67..a87fa0ae4 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -968,7 +968,7 @@ enum {
968 | PSSCAN_SMAPS 968 | PSSCAN_SMAPS
969 | PSSCAN_COMM, 969 | PSSCAN_COMM,
970 EXIT_MASK = 0, 970 EXIT_MASK = 0,
971 NO_RESCAN_MASK = (unsigned)-1, 971 ONLY_REDRAW = (unsigned)-1,
972}; 972};
973 973
974#if ENABLE_FEATURE_TOP_INTERACTIVE 974#if ENABLE_FEATURE_TOP_INTERACTIVE
@@ -984,12 +984,19 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
984 int32_t c, cc; 984 int32_t c, cc;
985 985
986 c = safe_read_key(STDIN_FILENO, G.kbd_input, interval * 1000); 986 c = safe_read_key(STDIN_FILENO, G.kbd_input, interval * 1000);
987 if (c == -1 && errno != EAGAIN) { 987 if (c == -1) {
988 /* error/EOF */ 988 if (errno != EAGAIN)
989 option_mask32 |= OPT_EOF; 989 /* error/EOF */
990 option_mask32 |= OPT_EOF;
991 /* else: timeout - rescan and refresh */
990 break; 992 break;
991 } 993 }
992 interval = 0; 994 interval = 0;
995 /* "continue" statements below return to do one additional
996 * quick attempt to read a key. This prevents
997 * long sequence of e.g. "nnnnnnnnnnnnnnnnnnnnnnnnnn"
998 * to cause lots of rescans.
999 */
993 1000
994 if (c == initial_settings.c_cc[VINTR]) 1001 if (c == initial_settings.c_cc[VINTR])
995 return EXIT_MASK; 1002 return EXIT_MASK;
@@ -1023,7 +1030,7 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
1023 G_scroll_ofs = ntop - 1; 1030 G_scroll_ofs = ntop - 1;
1024 if (G_scroll_ofs < 0) 1031 if (G_scroll_ofs < 0)
1025 G_scroll_ofs = 0; 1032 G_scroll_ofs = 0;
1026 return NO_RESCAN_MASK; 1033 return ONLY_REDRAW;
1027 } 1034 }
1028 1035
1029 cc = c; 1036 cc = c;
@@ -1083,7 +1090,7 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
1083 if (c == 's') { 1090 if (c == 's') {
1084 sort_field = (sort_field + 1) % NUM_SORT_FIELD; 1091 sort_field = (sort_field + 1) % NUM_SORT_FIELD;
1085 if (scan_mask == TOPMEM_MASK) 1092 if (scan_mask == TOPMEM_MASK)
1086 return NO_RESCAN_MASK; 1093 return ONLY_REDRAW;
1087 scan_mask = TOPMEM_MASK; 1094 scan_mask = TOPMEM_MASK;
1088 free(prev_hist); 1095 free(prev_hist);
1089 prev_hist = NULL; 1096 prev_hist = NULL;
@@ -1093,7 +1100,7 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
1093# endif 1100# endif
1094 if (c == 'r') { 1101 if (c == 'r') {
1095 inverted ^= 1; 1102 inverted ^= 1;
1096 continue; 1103 return ONLY_REDRAW;
1097 } 1104 }
1098# if ENABLE_FEATURE_TOP_SMP_CPU 1105# if ENABLE_FEATURE_TOP_SMP_CPU
1099 /* procps-2.0.18 uses 'C', 3.2.7 uses '1' */ 1106 /* procps-2.0.18 uses 'C', 3.2.7 uses '1' */
@@ -1115,8 +1122,8 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
1115 } 1122 }
1116# endif 1123# endif
1117# endif 1124# endif
1118 break; /* unknown key -> force refresh */ 1125 /* Unknown key. Eat remaining buffered input (if any) */
1119 } 1126 } /* while (1) */
1120 1127
1121 return scan_mask; 1128 return scan_mask;
1122} 1129}
@@ -1253,7 +1260,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1253#endif 1260#endif
1254 1261
1255 while (scan_mask != EXIT_MASK) { 1262 while (scan_mask != EXIT_MASK) {
1256 IF_FEATURE_TOP_INTERACTIVE(unsigned new_mask;) 1263 IF_FEATURE_TOP_INTERACTIVE(unsigned new_mask = scan_mask;)
1257 procps_status_t *p = NULL; 1264 procps_status_t *p = NULL;
1258 1265
1259 if (OPT_BATCH_MODE) { 1266 if (OPT_BATCH_MODE) {
@@ -1337,7 +1344,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1337 qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); 1344 qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort);
1338 } 1345 }
1339#endif 1346#endif
1340 IF_FEATURE_TOP_INTERACTIVE(display:) 1347 IF_FEATURE_TOP_INTERACTIVE(redraw:)
1341 IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { 1348 IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) {
1342 display_process_list(G.lines, col); 1349 display_process_list(G.lines, col);
1343 } 1350 }
@@ -1353,9 +1360,15 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1353 clearmems(); 1360 clearmems();
1354 sleep_for_duration(interval); 1361 sleep_for_duration(interval);
1355#else 1362#else
1356 new_mask = handle_input(scan_mask, interval); 1363 new_mask = handle_input(scan_mask,
1357 if (new_mask == NO_RESCAN_MASK) 1364 /* After "redraw with no rescan", have one
1358 goto display; 1365 * key timeout shorter that normal
1366 * (IOW: rescan sooner):
1367 */
1368 (new_mask == ONLY_REDRAW ? 1 : interval)
1369 );
1370 if (new_mask == ONLY_REDRAW)
1371 goto redraw;
1359 scan_mask = new_mask; 1372 scan_mask = new_mask;
1360 clearmems(); 1373 clearmems();
1361#endif 1374#endif