Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Jul 1997 14:13:34 +0200 (MET DST)
From:      Wolfram Schneider <wosch@apfel.de>
To:        David Nugent <davidn@labs.usn.blaze.net.au>
Cc:        current@FreeBSD.ORG
Subject:   Re: long usernames in top 
Message-ID:  <199707051213.OAA01662@panke.panke.de>
In-Reply-To: <199707051134.VAA01367@labs.usn.blaze.net.au>
References:  <199707051001.MAA00736@panke.panke.de> <199707051134.VAA01367@labs.usn.blaze.net.au>

next in thread | previous in thread | raw e-mail | index | archive | help
David Nugent writes:
>>  Here is a workaround. Top should print only the first 10
>>  characters. If the username is longer than 10 characters, the
>>  10th character will be replaces with an asterisk ('*').
>
>Yuck, yuck, yuck.
>
>int getmaxnamelen(void)
>{
>  int maxnamelen = 8;
>  struct passwd *pw;
>
>  setpwent();
>  while ((pw=getpwent()) != NULL) {
>    if (pw->pw_name) {
>      int nlen = strlen(pw->pw_name;
>      if (nlen > maxnamelen)
>        maxnamelen = nlen;
>    }
>  }
>  endpwent();
>  return maxnamelen > SOME_MAX_VALUE ? SOME_MAX_VALUE : maxnamelen;
>}
>
>Use this to determine the maximum name. 8 is an obvious minimum, and
>do this at startup. If larger names are added while top is running,
>well, tough, they get truncated which is no big deal.

Reading the whole password database is an overkill. Your NIS admin
will kill you ... think about environments with more than 5000 users.



>Sitting the length at some arbitrary small value is silly.

This may work for short usernames. But if someone use 32 or 64
character long usernames you must cut the name (or use the uid
instead the username).

-- 
Wolfram Schneider    <wosch@apfel.de>    http://www.apfel.de/~wosch/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707051213.OAA01662>