Bug 20799

Summary: top's problem
Product: Base System Reporter: wkwu <wkwu>
Component: binAssignee: Peter Wemm <peter>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   

Description wkwu 2000-08-23 11:30:01 UTC
We use yp for about 2000 users. Inside the 'top' source, 
/usr/src/usr.bin/top/machine.c: line 238:

    while ((pw = getpwent()) != NULL) {
        if (strlen(pw->pw_name) > namelength)
            namelength = strlen(pw->pw_name);
    }
    if (namelength < 8)
        namelength = 8;
    if (namelength > 15)
        namelength = 15; 

we have to comment above, and added only line:
	namelength = 9;

Because the 'top' command will delay about 7-seconds if we use
the original source. I am wondered why the 'top' dump all yp-passwd
to get 'namelength'. It seems a little stupid.

Fix: 

comment above, and added only line: (Maybe you have beeter idea:)
        namelength = 9;
Comment 1 Peter Pentchev 2000-08-23 12:09:59 UTC
If you want to hardcode a username length limit, you'd be better off
with the max value - 15, in this case; or use a value provided by
the OS - UT_NAMESIZE comes to mind.

On Wed, Aug 23, 2000 at 06:26:25PM +0800, wkwu@Kavalan.csie.NCTU.edu.tw wrote:
> >Synopsis:       top's problem
> 
> >Description:
[snip]
> 
> we have to comment above, and added only line:
> 	namelength = 9;
> 
> Because the 'top' command will delay about 7-seconds if we use
> the original source. I am wondered why the 'top' dump all yp-passwd
> to get 'namelength'. It seems a little stupid.

G'luck,
Peter

-- 
This inert sentence is my body, but my soul is alive, dancing in the sparks of your brain.
Comment 2 Sheldon Hearn freebsd_committer freebsd_triage 2000-08-23 12:46:09 UTC
Responsible Changed
From-To: freebsd-bugs->davidn

David, could you chat to Peter Wemm and find out whether his 
hackaround in rev 1.5 of machine.c is still required? 
Given that namelength is now doubly bounded, it seems 
to make sense that we hard-code 9 in there as suggested 
in this PR.
Comment 3 Doug Barton freebsd_committer freebsd_triage 2003-03-15 05:54:41 UTC
Responsible Changed
From-To: davidn->peter


davidn is no longer with us, and Peter seems to know something about this
Comment 4 Gavin Atkinson 2007-05-04 15:53:20 UTC
This is still a problem on 6.2.  PR bin/89762 is a duplicate of this,
but has a better solution which allows for compile-time configuration of
top(1) to avoid the issue.  Therefore this PR can probably be closed.
Comment 5 Remko Lodder freebsd_committer freebsd_triage 2007-05-04 19:35:32 UTC
State Changed
From-To: open->closed

duplicate of 89762, reported by gavin
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-05-20 23:19:32 UTC
A commit references this bug:

Author: eadler
Date: Sun May 20 23:19:10 UTC 2018
New revision: 333945
URL: https://svnweb.freebsd.org/changeset/base/333945

Log:
  top(1): set max username length based on system constant

  This changes previous behavior of calculating it at startup based on
  the current max username length.

  This is done because:
  - it is in theory possible for the max length to change at run-time
    (e.g., a new user is added after top starts running)
  - on machines with many users this delays startup significantly

  PR:		20799
  PR:		89762
  Reported by:	ob@e-Gitt.NET
  Reported by:	wkwu@Kavalan.csie.NCTU.edu.tw
  Reported on:	2000-08-23 and 2005-11-30

Changes:
  head/usr.bin/top/machine.c
  head/usr.bin/top/machine.h
  head/usr.bin/top/top.c
  head/usr.bin/top/username.c