From owner-freebsd-current Sat Sep 8 3:10:46 2001 Delivered-To: freebsd-current@freebsd.org Received: from elvis.mu.org (elvis.mu.org [216.33.66.196]) by hub.freebsd.org (Postfix) with ESMTP id C94BC37B401; Sat, 8 Sep 2001 03:10:42 -0700 (PDT) Received: by elvis.mu.org (Postfix, from userid 1192) id 892ED81D05; Sat, 8 Sep 2001 05:10:37 -0500 (CDT) Date: Sat, 8 Sep 2001 05:10:37 -0500 From: Alfred Perlstein To: Nick Hibma Cc: Thomas Quinot , current@FreeBSD.ORG Subject: Re: top(1) takes ages to start up Message-ID: <20010908051037.E2965@elvis.mu.org> References: <20010907163406.A18904@melusine.cuivre.fr.eu.org> <20010908104633.P575-100000@heather.plazza.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010908104633.P575-100000@heather.plazza.uk>; from n_hibma@FreeBSD.ORG on Sat, Sep 08, 2001 at 10:50:06AM +0100 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG * Nick Hibma [010908 04:51] wrote: > > Why don't you add an early-out for namelength => 15 or put the > if-statement in the loop: This is a good idea, however it fails for the case when everyone has been assigned usernames that are less than 15 characters, I would suggest putting an upper bounds on the amount of times you'll call getpwent() to something like 200 or some other compile time (but command line over-rideable) number before defaulting to the max. > > Index: machine.c > =================================================================== > RCS file: /home/ncvs/src/usr.bin/top/machine.c,v > retrieving revision 1.44 > diff -u -r1.44 machine.c > --- machine.c 2001/05/31 22:36:51 1.44 > +++ machine.c 2001/09/08 09:48:03 > @@ -216,13 +216,16 @@ > while ((pw = getpwent()) != NULL) { > if (strlen(pw->pw_name) > namelength) > namelength = strlen(pw->pw_name); > + if (smpmode && namelength > 13) { > + namelength = 13; > + break; > + } else if (namelength > 15) { > + namelength = 15; > + break; > + } > } > if (namelength < 8) > namelength = 8; > - if (smpmode && namelength > 13) > - namelength = 13; > - else if (namelength > 15) > - namelength = 15; > > if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, > "kvm_open")) == NULL) > return -1; > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message