Small patch to fix top in large NIS environments

David Frascone dave at frascone.com
Wed Jan 9 14:24:25 PST 2008


Oops -- should have checked -- I am not used to working as root, so root
didn't have my normal .cvsrc.  Unified diff attached.

-Dave

On Jan 9, 2008 12:15 PM, David Frascone <dave at frascone.com> wrote:

>
> The -u flag to top is supposed to limit uid lookups.  But, it was still
> spinning through the entire password database with while (getpwent()).  At
> Cisco, which has a fairly large NIS database, this takes forever, and top
> never starts.
>
> I filed this bug to address it:
> http://www.freebsd.org/cgi/query-pr.cgi?pr=119490
>
> The attached patch fixes it.  This is my first submission, so let me know
> if this is the proper order, etc, to post the patches ( i.e. file the bug,
> the post a fix)
>
> -Dave
>
-------------- next part --------------
Index: usr.bin/top/machine.c
===================================================================
RCS file: /usr/FreeBSD/cvsup/src/usr.bin/top/machine.c,v
retrieving revision 1.83
diff -u -r1.83 machine.c
--- usr.bin/top/machine.c	26 Oct 2007 08:00:40 -0000	1.83
+++ usr.bin/top/machine.c	9 Jan 2008 17:08:32 -0000
@@ -223,7 +223,7 @@
 static int swapmode(int *retavail, int *retfree);
 
 int
-machine_init(struct statics *statics)
+machine_init(struct statics *statics, char do_unames)
 {
 	int pagesize;
 	size_t modelen;
@@ -237,9 +237,11 @@
 	    modelen != sizeof(smpmode))
 		smpmode = 0;
 
-	while ((pw = getpwent()) != NULL) {
+	if (do_unames) {
+	    while ((pw = getpwent()) != NULL) {
 		if (strlen(pw->pw_name) > namelength)
 			namelength = strlen(pw->pw_name);
+	    }
 	}
 	if (smpmode && namelength > SMPUNAMELEN)
 		namelength = SMPUNAMELEN;
Index: contrib/top/top.c
===================================================================
RCS file: /usr/FreeBSD/cvsup/src/contrib/top/top.c,v
retrieving revision 1.23
diff -u -r1.23 top.c
--- contrib/top/top.c	4 May 2007 15:42:58 -0000	1.23
+++ contrib/top/top.c	9 Jan 2008 17:08:56 -0000
@@ -450,7 +450,7 @@
     }
 
     /* initialize the kernel memory interface */
-    if (machine_init(&statics) == -1)
+    if (machine_init(&statics, do_unames) == -1)
     {
 	exit(1);
     }


More information about the freebsd-current mailing list