bin/105860: top(1) user ID misalignment in mixer username/uid mode

Giorgos Keramidas keramida at FreeBSD.org
Sun Nov 26 01:20:09 PST 2006


>Number:         105860
>Category:       bin
>Synopsis:       top(1) user ID misalignment in mixer username/uid mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 26 09:20:07 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Giorgos Keramidas
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
FreeBSD
>Environment:
System: FreeBSD kobe 7.0-CURRENT FreeBSD 7.0-CURRENT #0: \
Sat Nov 25 13:14:50 EET 2006 build at kobe:/home/build/obj/home/build/src/sys/KOBE i386

>Description:

While running top(1) inside a chroot, processes whose user ID cannot
be mapped back to a username (i.e. because the chroot lacks the proper
entries in its password database files), are shown in what seems a
mildly "funny" way.

Note the misalignment of '1000' in the lines owned by my non-root
user below.  The user ID numbers are neither aligned with the
'USERNAME' header, nor with the rest of the lines.

% last pid: 22288;  load averages:  0.40,  0.41,  0.34    up 0+04:22:53  01:14:37
% 53 processes:  2 running, 50 sleeping, 1 lock
% CPU states:  0.0% user,  0.0% nice,  0.0% system,  0.0% interrupt,  100% idle
% Mem: 122M Active, 143M Inact, 140M Wired, 21M Cache, 59M Buf, 60M Free
% Swap: 2300M Total, 44K Used, 2300M Free
% 
%   PID USERNAME  THR PRI NICE   SIZE    RES STATE  C   TIME    CPU COMMAND
%   955   1000      1  96    0   279M 19268K select 0   8:01  1.81% Xorg
%   450 root        1  96    0  5164K   772K select 0   0:30  1.66% moused
% 22288 root        1  96    0  5480K  1520K CPU0   0   0:01  0.93% top
%  1215   1000      1  96    0 12384K  5632K RUN    0   0:33  0.73% xterm
%   990   1000      1  96    0 10336K  4600K select 0   3:27  0.00% xterm

This is a result of the way user ID numbers are displayed by top's
display code.  When a user ID cannot (or should not, because of the
way top is configured to run) be mapped back to a username string,
the string displayed by top in that column is generated by itoa7()
from `src/contrib/top/utils.c'.  This function formats a numeric
value to a hardcoded width of 7 characters, and right-aligns the
formatted value.  This is a bug for various minor reasons though.

  * It fails to account for the value of `namelen' which can be
    both smaller and larger than 7.  In fact, the default value
    of namelength in src/usr.bin/top/machine.c is 8 right now.

  * Even if only numeric IDs are printed, our current uid_t is
    at least 32-bits wide, so it can easily take values which
    cannot fit in 7-columns.

The best way to solve this would probably be to change both the
username() and itoa7() functions to something which can accept an
extra argument -- the value of namelength.  Then, we can let them
decice if they want to left-align, right-align, and how they will
padd the string they return in a more intelligent manner.

>How-To-Repeat:
>Fix:

None yet, but I'm working on it.

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list