Bug 105860 - top(1) user ID misalignment in mixer username/uid mode
Summary: top(1) user ID misalignment in mixer username/uid mode
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 7.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-26 09:20 UTC by Giorgos Keramidas
Modified: 2022-04-23 13:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giorgos Keramidas freebsd_committer freebsd_triage 2006-11-26 09:20:07 UTC
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.

Fix: 

None yet, but I'm working on it.
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:10 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped