Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 May 2018 23:37:31 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r333946 - head/usr.bin/top
Message-ID:  <201805202337.w4KNbVCb048138@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Sun May 20 23:37:30 2018
New Revision: 333946
URL: https://svnweb.freebsd.org/changeset/base/333946

Log:
  top(1): pull configuration directly into header files
  
  This sets configuration variables directly in the various header files,
  avoiding the need to have special logic in our Makefile to build the
  header.

Deleted:
  head/usr.bin/top/top.local.hs
  head/usr.bin/top/top.xs
Modified:
  head/usr.bin/top/Makefile
  head/usr.bin/top/top.c
  head/usr.bin/top/top.h
  head/usr.bin/top/username.c
  head/usr.bin/top/username.h

Modified: head/usr.bin/top/Makefile
==============================================================================
--- head/usr.bin/top/Makefile	Sun May 20 23:19:09 2018	(r333945)
+++ head/usr.bin/top/Makefile	Sun May 20 23:37:30 2018	(r333946)
@@ -16,15 +16,4 @@ SIGNAL_H= ${SRCTOP}/sys/sys/signal.h
 sigdesc.h: sigconv.awk ${SIGNAL_H}
 	awk -f ${SRCTOP}/usr.bin/top/sigconv.awk < ${SIGNAL_H} > ${.TARGET}
 
-.SUFFIXES: .xs .x .hs .h
-.xs.x .hs.h:
-	@${ECHO} Making ${.TARGET} from ${.IMPSRC}
-	@sed -e's,%LoadMax%,5.0,g' \
-	-e's,%TableSize%,20011,g' \
-	-e's,%NominalTopn%,18,g' \
-	-e's,%topn%,-1,g' \
-	-e's,%delay%,2,g' \
-	-e's,%random%,1,g' \
-	${.IMPSRC} > ${.TARGET}
-
 .include <bsd.prog.mk>

Modified: head/usr.bin/top/top.c
==============================================================================
--- head/usr.bin/top/top.c	Sun May 20 23:19:09 2018	(r333945)
+++ head/usr.bin/top/top.c	Sun May 20 23:37:30 2018	(r333946)
@@ -251,7 +251,7 @@ char *argv[];
     static char tempbuf1[50];
     static char tempbuf2[50];
     int old_sigmask;		/* only used for BSD-style signals */
-    int topn = Default_TOPN;
+    int topn = Infinity;
     int delay = Default_DELAY;
     int displays = 0;		/* indicates unspecified */
     int sel_ret = 0;
@@ -268,9 +268,7 @@ char *argv[];
     char do_unames = Yes;
     char interactive = Maybe;
     char warnings = 0;
-#if Default_TOPN == Infinity
     char topn_specified = No;
-#endif
     char ch;
     char *iptr;
     char no_command = 1;
@@ -525,12 +523,10 @@ char *argv[];
 			myname);
 		warnings++;
 	    }
-#if Default_TOPN == Infinity
             else
 	    {
 		topn_specified = Yes;
 	    }
-#endif
 	}
 
 	/* tricky:  remember old value of preset_argc & set preset_argc = 0 */
@@ -608,12 +604,8 @@ char *argv[];
 	 *  and the default is Infinity, then (and only then) we use
 	 *  "Nominal_TOPN" instead.
 	 */
-#if Default_TOPN == Infinity
 	topn = smart_terminal ? Largest :
 		    (topn_specified ? Largest : Nominal_TOPN);
-#else
-	topn = Largest;
-#endif
     }
 
     /* set header display accordingly */

Modified: head/usr.bin/top/top.h
==============================================================================
--- head/usr.bin/top/top.h	Sun May 20 23:19:09 2018	(r333945)
+++ head/usr.bin/top/top.h	Sun May 20 23:37:30 2018	(r333946)
@@ -10,8 +10,7 @@
 #ifndef TOP_H
 #define TOP_H
 
-/* Current major version number */
-#define VERSION		3
+#define Default_DELAY 2
 
 /* Number of lines of header information on the standard screen */
 extern int Header_lines;	/* 7 */
@@ -48,5 +47,33 @@ extern int pcpu_stats;
 
 char* kill_procs(char *);
 char* renice_procs(char *);
+
+/*
+ *  The space command forces an immediate update.  Sometimes, on loaded
+ *  systems, this update will take a significant period of time (because all
+ *  the output is buffered).  So, if the short-term load average is above
+ *  "LoadMax", then top will put the cursor home immediately after the space
+ *  is pressed before the next update is attempted.  This serves as a visual
+ *  acknowledgement of the command.
+ */
+#define LoadMax  5.0
+
+/*
+ *  "Nominal_TOPN" is used as the default TOPN when 
+ *  the output is a dumb terminal.  If we didn't do this, then
+ *  we will get every
+ *  process in the system when running top on a dumb terminal (or redirected
+ *  to a file).  Note that Nominal_TOPN is a default:  it can still be
+ *  overridden on the command line, even with the value "infinity".
+ */
+#define Nominal_TOPN	18
+
+/*
+ *  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.  
+ */
+
+#define RANDOM_PW	1
 
 #endif /* TOP_H */

Modified: head/usr.bin/top/username.c
==============================================================================
--- head/usr.bin/top/username.c	Sun May 20 23:19:09 2018	(r333945)
+++ head/usr.bin/top/username.c	Sun May 20 23:37:30 2018	(r333946)
@@ -1,6 +1,5 @@
 /*
  *  Top users/processes display for Unix
- *  Version 3
  *
  *  This program may be freely redistributed,
  *  but this entire comment MUST remain intact.
@@ -131,54 +130,20 @@ int wecare;		/* 1 = enter it always, 0 = nice to have 
 /*
  * 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.
+ * just handle this uid.
  */
 
-int get_user(uid)
-
-int uid;
-
+int
+get_user(int 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, itoa7(uid), 1));
 }

Modified: head/usr.bin/top/username.h
==============================================================================
--- head/usr.bin/top/username.h	Sun May 20 23:19:09 2018	(r333945)
+++ head/usr.bin/top/username.h	Sun May 20 23:37:30 2018	(r333946)
@@ -20,4 +20,14 @@ void	 init_hash(void);
 char 	*username(int uid);
 int 	 userid(char *username);
 
+/*
+ *  "Table_size" defines the size of the hash tables used to map uid to
+ *  username.  The number of users in /etc/passwd CANNOT be greater than
+ *  this number.  If the error message "table overflow: too many users"
+ *  is printed by top, then "Table_size" needs to be increased.  Things will
+ *  work best if the number is a prime number that is about twice the number
+ *  of lines in /etc/passwd.
+ */
+#define Table_size	20011
+
 #endif /* USERNAME_H */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805202337.w4KNbVCb048138>