From owner-freebsd-current Sat Jul 5 05:15:09 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id FAA04285 for current-outgoing; Sat, 5 Jul 1997 05:15:09 -0700 (PDT) Received: from bsd.fs.bauing.th-darmstadt.de (bsd.fs.bauing.th-darmstadt.de [130.83.63.241]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id FAA04280 for ; Sat, 5 Jul 1997 05:15:07 -0700 (PDT) Received: from panke.panke.de (anonymous213.ppp.cs.tu-berlin.de [130.149.17.213]) by bsd.fs.bauing.th-darmstadt.de (8.8.5/8.8.5) with ESMTP id OAA27138; Sat, 5 Jul 1997 14:15:03 +0200 (MET DST) Received: (from wosch@localhost) by panke.panke.de (8.8.5/8.6.12) id OAA01662; Sat, 5 Jul 1997 14:13:34 +0200 (MET DST) Date: Sat, 5 Jul 1997 14:13:34 +0200 (MET DST) Message-Id: <199707051213.OAA01662@panke.panke.de> From: Wolfram Schneider To: David Nugent Cc: current@FreeBSD.ORG Subject: Re: long usernames in top In-Reply-To: <199707051134.VAA01367@labs.usn.blaze.net.au> References: <199707051001.MAA00736@panke.panke.de> <199707051134.VAA01367@labs.usn.blaze.net.au> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-current@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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 http://www.apfel.de/~wosch/