From keramida@ceid.upatras.gr  Sun Nov 26 09:11:01 2006
Return-Path: <keramida@ceid.upatras.gr>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 3823716A407
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 26 Nov 2006 09:11:01 +0000 (UTC)
	(envelope-from keramida@ceid.upatras.gr)
Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B6C6843D45
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 26 Nov 2006 09:10:05 +0000 (GMT)
	(envelope-from keramida@ceid.upatras.gr)
Received: from kobe.laptop (evge.static.otenet.gr [212.205.236.117])
	(authenticated bits=128)
	by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id kAQ9AVYL012443
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT)
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 26 Nov 2006 11:10:35 +0200
Received: from kobe.laptop (kobe.laptop [127.0.0.1])
	by kobe.laptop (8.13.8/8.13.8) with ESMTP id kAQ9ACcl027130
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 26 Nov 2006 11:10:16 +0200 (EET)
	(envelope-from keramida@kobe.laptop)
Received: (from keramida@localhost)
	by kobe.laptop (8.13.8/8.13.8/Submit) id kAQ1Qi8s022369;
	Sun, 26 Nov 2006 03:26:44 +0200 (EET)
	(envelope-from keramida)
Message-Id: <200611260126.kAQ1Qi8s022369@kobe.laptop>
Date: Sun, 26 Nov 2006 03:26:44 +0200 (EET)
From: Giorgos Keramidas <keramida@freebsd.org>
Reply-To: Giorgos Keramidas <keramida@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: top(1) user ID misalignment in mixer username/uid mode
X-Send-Pr-Version: 3.113

>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@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:
