ps and username size

Denis Vlasenko vda.linux at googlemail.com
Sat Feb 2 16:19:04 UTC 2008


On Thursday 10 January 2008 22:07, Tito wrote:
> On Thursday 10 January 2008 22:40:26 Cristian Ionescu-Idbohrn wrote:
> > On Thu, 10 Jan 2008, Tito wrote:
> > 
> > > Isn't there a maximum lenght for usernames on unix/linux?
> > > Would it make sense to set the width of this field to that value?
> > 
> > Doing so seems like the clever thing to do, though you'd run into a
> > columnisation problem and loose compatibility to full version of the app.
> > 
> > > I ask this because on my system (Ubuntu 7.10 - more or less)
> > > adduser  fails with usernames longer than 32 chars.
> > >
> > > Adding user `qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq' ...
> > > Adding new group `qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq' (1006) ...
> > > groupadd: qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq is not a valid group name
> > > adduser: `/usr/sbin/groupadd -g 1006 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq' returned error code 3. Exiting.
> > 
> > 32 chars seems reasonable, but display real estate seems to be a problem.
> > I believe truncated usernames vs. option to display user ids only seems to
> > be an acceptable compromise.  What do you think?
> > 
> > 
> > Cheers,
> > 
> 
> Hi,
> of course it is acceptable.
> 
> OTOH it doesn't solve the problem of a possible ambiguity
> between username and uid as names composed only of digits
> are legal.

I think we can right-justify IDs:

static void func_user(char *buf, int size, const procps_status_t *ps)
{
        /* procps 2.18 shows numeric UID if name overflows the field */
        /* TODO: get_cached_username() returns numeric string if
         * user has no passwd record, we will display it
         * left-justified here; too long usernames are shown
         * as _right-justified_ IDs. Is it worth fixing? */
        const char *user = get_cached_username(ps->uid);
        if (strlen(user) <= size)
                safe_strncpy(buf, get_cached_username(ps->uid), size+1);
        else
                sprintf(buf, "%*u", size, (unsigned)ps->uid);
}

Output:

# ./busybox ps
PID   USER     TIME   COMMAND
    1 root       0:00 /bin/sh /init
    2 root       0:00 [kthreadd]
    3 root       0:00 [migration/0]
...
  542 root       0:00 [kjournald]
  560 root       0:01 udevd
  570 root       0:00 [reiserfs/0]
  577 1          0:00 rpc.portmap     <================ UID with no matching passwd record
  630 root       0:00 runsvdir -P /var/service
  632 root       0:00 runsv fw
  634 root       0:00 runsv gpm
  635 root       0:00 gpm -D -2 -m /dev/psaux -t ps2
  636 root       0:00 runsv ntp
  637       65   0:00 svlogd -tt /var/log/service/ntp  <========= Username is too long
  638 root       0:00 runsv top
  639 user0      0:07 top
  640 root       0:00 runsv klog
  641       65   0:00 svlogd -tt /var/log/service/klog
  642 root       0:00 socklog ucspi

But wouldn't it go against bbox's size saving goal
to have this feature? Is it really necessary?
--
vda



More information about the busybox mailing list