11.1-RELEASE: new line containing garbage added to "top"

Peter pmc at citylink.dinoex.sub.org
Fri Jul 28 18:13:36 UTC 2017


Glen Barber wrote:
> On Fri, Jul 28, 2017 at 03:24:50PM +0200, Peter wrote:
>> After upgrading to 11.1-RELEASE, a new line appears in the output of "top"
>> which contains rubbish:
>>
>>> last pid: 10789;  load averages:  5.75,  5.19,  3.89    up 0+00:34:46 03:23:51
>>> 1030 processes:9 running, 1004 sleeping, 17 waiting
>>> CPU 0: 16.0% user,  0.0% nice, 78.7% system,  4.9% interrupt,  0.4% idle
>>> CPU 1:  8.0% user,  0.0% nice, 82.5% system,  9.1% interrupt,  0.4% idle
>>> Mem: 218M Active, 34M Inact, 105M Laundry, 600M Wired, 18M Buf, 34M Free
>>> ARC: 324M Total, 54M MFU, 129M MRU, 2970K Anon, 13M Header, 125M Other
>>>      136¿176M Compress185 194M Uncompressed361.94:1 Ratio
>>> Swap: 2441M Total, 277M Used, 2164M Free, 11% Inuse
>>
>>>   PID USERNAME   PRI NICE   SIZE    RES STATE   C   TIME    WCPU COMMAND
>> ..
>>
>>
>> That looks funny. But I dont like it.
>>
>
> It appears to be fixed in 11-STABLE (r321419).
>
> Glen
>

I don't think so. At least there is nothing in the commitlog. r318449 is 
the last commit in 11-STABLE for the respective file; and thats before 
the 11.1-RELEASE branch.

The error is in the screen-formatting in "top", and that error was 
already present back in 1997 (and probably earlier), and it is also 
present in HEAD.

What "top" does is basically this:

 > char *string = some_buffer_to_print;
 > printf("%.5s", &string[-4]);

A negative index on a string usually yields a nullified area. (Except if 
otherwise *eg*) Thats why we usually don't see the matter - nullbytes 
are invisible on screen.

Fix is very simple:

Index: contrib/top/display.c
===================================================================
--- display.c   (revision 321434)
+++ display.c   (working copy)
@@ -1310,7 +1310,7 @@
         cursor_on_line = Yes;
         putchar(ch);
         *old = ch;
-       lastcol = 1;
+       lastcol++;
      }
      old++;


---------------------------------------------------------
Then, since I was at it, I decided to beautify the proc display as well, 
as I usually see >1000 procs:


--- display.c   (revision 321434)
+++ display.c   (working copy)
@@ -100,7 +100,7 @@
  int  y_loadave =       0;
  int  x_procstate =     0;
  int  y_procstate =     1;
-int  x_brkdn =         15;
+int  x_brkdn =         16;
  int  y_brkdn =         1;
  int  x_mem =           5;
  int  y_mem =           3;
@@ -373,9 +373,9 @@
      printf("%d processes:", total);
      ltotal = total;

-    /* put out enough spaces to get to column 15 */
+    /* put out enough spaces to get to column 16 */
      i = digits(total);
-    while (i++ < 4)
+    while (i++ < 5)
      {
         putchar(' ');
      }


----------------------------------------------------------------
Then, concerning the complaint about the empty line (bug #220996), I 
couldn't really reproduce this. But it seems that specifically this 
issue was already fixed in HEAD by this one here: 
https://reviews.freebsd.org/D11693

----------------------------------------------------------------
Now, can anybody make the above snippets appear in HEAD and 11-STABLE?



More information about the freebsd-stable mailing list