summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-04-02 16:41:25 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-04-02 16:41:25 +0000
commitcdb27bf66b25c49025564c9616441d3f762bfc6c (patch)
tree13f52504eb68a32499c269b25eb9bc66c5540301 /usr.bin
parent080ccca067c8e630dc50b6717df67c9c935ea059 (diff)
using getpwent() in a loop is so 1980; ok millert
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/top/top.local.h47
-rw-r--r--usr.bin/top/username.c31
2 files changed, 2 insertions, 76 deletions
diff --git a/usr.bin/top/top.local.h b/usr.bin/top/top.local.h
index b2f3c8bacc9..f13a8ace66b 100644
--- a/usr.bin/top/top.local.h
+++ b/usr.bin/top/top.local.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.local.h,v 1.3 2002/07/15 17:20:36 deraadt Exp $ */
+/* $OpenBSD: top.local.h,v 1.4 2008/04/02 16:41:24 deraadt Exp $ */
/*
* Top - a top users display for Berkeley Unix
@@ -51,48 +51,3 @@
#ifndef Default_DELAY
#define Default_DELAY 5
#endif
-
-/*
- * Top users/processes display for Unix
- * Version 3
- *
- * Copyright (c) 1984, 1989, William LeFebvre, Rice University
- * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR OR HIS EMPLOYER BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * If the local system's getpwnam interface uses random access to retrieve
- * a record (i.e.: 4.3 systems, Sun "yellow pages"), then defining
- * RANDOM_PW will take advantage of that fact. If RANDOM_PW is defined,
- * then getpwnam is used and the result is cached. If not, then getpwent
- * is used to read and cache the password entries sequentially until the
- * desired one is found.
- *
- * We initially set RANDOM_PW to something which is controllable by the
- * Configure script. Then if its value is 0, we undef it.
- */
-
-#define RANDOM_PW 1
-#if RANDOM_PW == 0
-#undef RANDOM_PW
-#endif
diff --git a/usr.bin/top/username.c b/usr.bin/top/username.c
index 851e4e87099..a08a8593519 100644
--- a/usr.bin/top/username.c
+++ b/usr.bin/top/username.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: username.c,v 1.14 2004/05/09 22:14:15 deraadt Exp $ */
+/* $OpenBSD: username.c,v 1.15 2008/04/02 16:41:24 deraadt Exp $ */
/*
* Top users/processes display for Unix
@@ -134,45 +134,16 @@ enter_user(uid_t uid, char *name, int wecare)
/*
* Get a userid->name mapping from the system.
- * If the passwd database is hashed (#define RANDOM_PW), we
- * just handle this uid. Otherwise we scan the passwd file
- * and cache any entries we pass over while looking.
*/
static int
get_user(uid_t uid)
{
struct passwd *pwd;
-#ifdef RANDOM_PW
/* no performance penalty for using getpwuid makes it easy */
if ((pwd = getpwuid(uid)) != NULL)
return (enter_user(pwd->pw_uid, pwd->pw_name, 1));
-#else
- int from_start = 0;
-
- /*
- * If we just called getpwuid each time, things would be very slow
- * since that just iterates through the passwd file each time. So,
- * we walk through the file instead (using getpwent) and cache each
- * entry as we go. Once the right record is found, we cache it and
- * return immediately. The next time we come in, getpwent will get
- * the next record. In theory, we never have to read the passwd file
- * a second time (because we cache everything we read). But in
- * practice, the cache may not be large enough, so if we don't find
- * it the first time we have to scan the file a second time. This
- * is not very efficient, but it will do for now.
- */
- while (from_start++ < 2) {
- while ((pwd = getpwent()) != NULL) {
- if (pwd->pw_uid == uid)
- return (enter_user(pwd->pw_uid, pwd->pw_name, 1));
- (void) enter_user(pwd->pw_uid, pwd->pw_name, 0);
- }
- /* try again */
- setpwent();
- }
-#endif
/* if we can't find the name at all, then use the uid as the name */
return (enter_user(uid, format_uid(uid), 1));
}