summaryrefslogtreecommitdiffstats
path: root/bin/ps/nlist.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-06-30 21:34:14 +0000
committerphk <phk@FreeBSD.org>1998-06-30 21:34:14 +0000
commit167a14bcd4260afeb7ee50cb39ec42780cc7116d (patch)
tree05167827fa9f47759008474918dde7f17857bd5d /bin/ps/nlist.c
parent6658078ab314ed6133739f3639793c8fde5b5a71 (diff)
downloadFreeBSD-src-167a14bcd4260afeb7ee50cb39ec42780cc7116d.zip
FreeBSD-src-167a14bcd4260afeb7ee50cb39ec42780cc7116d.tar.gz
Pick up kernel variables/constants using sysctl rather than through /dev/mem
Use /dev/null for opening the kvm library, we don't need access to /dev/mem anymore. ps can now run without the setgid(kmem) bit. If it does it will not be able to show argv/envp for another uid's processes unless you are root.
Diffstat (limited to 'bin/ps/nlist.c')
-rw-r--r--bin/ps/nlist.c83
1 files changed, 7 insertions, 76 deletions
diff --git a/bin/ps/nlist.c b/bin/ps/nlist.c
index 46ade5d..47aa6e9 100644
--- a/bin/ps/nlist.c
+++ b/bin/ps/nlist.c
@@ -31,93 +31,24 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)nlist.c 8.4 (Berkeley) 4/2/94";
-#endif
-static const char rcsid[] =
- "$Id$";
-#endif /* not lint */
-
-#include <sys/param.h>
#include <sys/time.h>
-#include <sys/proc.h>
#include <sys/resource.h>
-#include <err.h>
-#include <errno.h>
-#include <kvm.h>
-#include <nlist.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "ps.h"
-
-struct nlist psnl[] = {
- {"_fscale"},
-#define X_FSCALE 0
- {"_ccpu"},
-#define X_CCPU 1
- {"_avail_start"},
-#define X_AVAILSTART 2
- {"_avail_end"},
-#define X_AVAILEND 3
- {NULL}
-};
-
fixpt_t ccpu; /* kernel _ccpu variable */
int nlistread; /* if nlist already read. */
int mempages; /* number of pages of phys. memory */
int fscale; /* kernel _fscale variable */
-extern kvm_t *kd;
-
-#define kread(x, v) \
- kvm_read(kd, psnl[x].n_value, (char *)&v, sizeof v) != sizeof(v)
-
int
donlist()
{
- int rval;
- int tmp;
- rval = 0;
- nlistread = 1;
- if (kvm_nlist(kd, psnl)) {
- nlisterr(psnl);
- eval = 1;
+ if (sysctlbyname("kern.ccpu", &ccpu, sizeof ccpu, 0, 0) < 0)
return (1);
- }
- if (kread(X_FSCALE, fscale)) {
- warnx("fscale: %s", kvm_geterr(kd));
- eval = rval = 1;
- }
- if (kread(X_AVAILEND, mempages)) {
- warnx("avail_start: %s", kvm_geterr(kd));
- eval = rval = 1;
- }
- if (kread(X_AVAILSTART, tmp)) {
- warnx("avail_end: %s", kvm_geterr(kd));
- eval = rval = 1;
- }
- mempages -= tmp;
- mempages /= PAGE_SIZE;
- if (kread(X_CCPU, ccpu)) {
- warnx("ccpu: %s", kvm_geterr(kd));
- eval = rval = 1;
- }
- return (rval);
-}
-
-void
-nlisterr(nl)
- struct nlist nl[];
-{
- int i;
-
- (void)fprintf(stderr, "ps: nlist: can't find following symbols:");
- for (i = 0; nl[i].n_name != NULL; i++)
- if (nl[i].n_value == 0)
- (void)fprintf(stderr, " %s", nl[i].n_name);
- (void)fprintf(stderr, "\n");
+ if (sysctlbyname("kern.fscale", &fscale, sizeof fscale, 0, 0) < 0)
+ return (1);
+ if (sysctlbyname("hw.availpages", &mempages, sizeof mempages, 0, 0) < 0)
+ return (1);
+ nlistread = 1;
+ return (0);
}
OpenPOWER on IntegriCloud