From 2de91e85be3fed7b0fa5a8634d93a2164f84b6ed Mon Sep 17 00:00:00 2001
From: albert <>
Date: Sat, 19 Oct 2002 08:49:00 +0000
Subject: [PATCH] fix top for 2.5.xx

---
 NEWS  |  1 +
 top.c | 14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index bd10a778..625e339a 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Linux 2.2.xx ELF note warning removed
 only show IO-wait on recent kernels
 fix top's SMP stats
 fix top for "dumb" and "vt510" terminals
+in top, limit the priority values to -99 ... 99
 
 procps-3.0.2 --> procps-3.0.3
 
diff --git a/top.c b/top.c
index 2d386c8b..a3ae459a 100644
--- a/top.c
+++ b/top.c
@@ -871,6 +871,9 @@ static proc_t **refreshprocs (proc_t **table, int flags)
 {
 #define PTRsz  sizeof(proc_t *)         /* eyeball candy */
 #define ENTsz  sizeof(proc_t)
+           /* quick & dirty response to 2.5.xx RT */
+#define RTx(p) { if (-99 > p->priority) p->priority = -99; \
+                 if (+99 < p->priority) p->priority = +99; }
    static unsigned savmax = 0;          /* first time, Bypass: (i)  */
    proc_t *ptsk = (proc_t *)-1;         /* first time, Force: (ii)  */
    unsigned curmax = 0;                 /* every time  (jeeze)      */
@@ -890,6 +893,7 @@ static proc_t **refreshprocs (proc_t **table, int flags)
          table[curmax]->cmdline = NULL;
       }
       if (!(ptsk = readproc(PT, table[curmax]))) break;
+      RTx(ptsk)
       ++curmax;
    }
 
@@ -898,8 +902,10 @@ static proc_t **refreshprocs (proc_t **table, int flags)
          /* realloc as we go, keeping 'table' ahead of 'currmax++' */
       table = alloc_r(table, (curmax + 1) * PTRsz);
          /* here, readproc will allocate the underlying proc_t stg */
-      if ((ptsk = readproc(PT, NULL)))
+      if ((ptsk = readproc(PT, NULL))) {
+         RTx(ptsk)
          table[curmax++] = ptsk;
+      }
    }
    closeproc(PT);
 
@@ -916,6 +922,7 @@ static proc_t **refreshprocs (proc_t **table, int flags)
 
 #undef PTRsz
 #undef ENTsz
+#undef RTx
 }
 
 
@@ -1931,10 +1938,11 @@ static void show_a_task (WIN_t *q, proc_t *task)
 {
    /* the following macro is our means to 'inline' emitting a column -- that's
       far and away the most frequent and costly part of top's entire job! */
-#define MKCOL(q,idx,sta,pad,buf,arg...) \
+#define MKCOL(q,idx,sta,pad,buf,arg...) do{ \
            if (!b) \
               snprintf(buf, sizeof(buf), f, ## arg); \
-           else mkcol(q, idx, sta, pad, buf, ## arg);
+           else mkcol(q, idx, sta, pad, buf, ## arg); }while(0)
+
    char rbuf[ROWBUFSIZ];
    int j, x, pad;
 
-- 
2.40.0