be more informative and careful about error conditions
[unix-history] / usr / src / bin / ps / nlist.c
... / ...
CommitLineData
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#ifndef lint
9static char sccsid[] = "@(#)nlist.c 5.7 (Berkeley) %G%";
10#endif /* not lint */
11
12#include <sys/param.h>
13#include <sys/time.h>
14#include <sys/proc.h>
15#include <sys/resource.h>
16#include <nlist.h>
17#include <errno.h>
18#include <stdio.h>
19#include <string.h>
20#include <kvm.h>
21#include "ps.h"
22
23#ifdef SPPWAIT
24#define NEWVM
25#endif
26
27struct nlist psnl[] = {
28 {"_fscale"},
29#define X_FSCALE 0
30 {"_ccpu"},
31#define X_CCPU 1
32#ifdef NEWVM
33 {"_avail_start"},
34#define X_AVAILSTART 2
35 {"_avail_end"},
36#define X_AVAILEND 3
37#else
38 {"_ecmx"},
39#define X_ECMX 2
40#endif
41 {NULL}
42};
43
44fixpt_t ccpu; /* kernel _ccpu variable */
45int nlistread; /* if nlist already read. */
46int mempages; /* number of pages of phys. memory */
47int fscale; /* kernel _fscale variable */
48
49extern kvm_t *kd;
50
51#define kread(x, v) \
52 kvm_read(kd, psnl[x].n_value, (char *)&v, sizeof v) != sizeof(v)
53
54int
55donlist()
56{
57 extern int eval;
58 int rval;
59#ifdef NEWVM
60 int tmp;
61#endif
62
63 rval = 0;
64 nlistread = 1;
65 if (kvm_nlist(kd, psnl)) {
66 nlisterr(psnl);
67 eval = 1;
68 return(1);
69 }
70 if (kread(X_FSCALE, fscale)) {
71 (void)fprintf(stderr, "ps: fscale: %s\n", kvm_geterr(kd));
72 eval = rval = 1;
73 }
74#ifdef NEWVM
75 if (kread(X_AVAILEND, mempages)) {
76 (void)fprintf(stderr, "ps: avail_start: %s\n", kvm_geterr(kd));
77 eval = rval = 1;
78 }
79 if (kread(X_AVAILSTART, tmp)) {
80 (void)fprintf(stderr, "ps: avail_end: %s\n", kvm_geterr(kd));
81 eval = rval = 1;
82 }
83 mempages -= tmp;
84#else
85 if (kread(X_ECMX, mempages)) {
86 (void)fprintf(stderr, "ps: ecmx: %s\n", kvm_geterr(kd));
87 eval = rval = 1;
88 }
89#endif
90 if (kread(X_CCPU, ccpu)) {
91 (void)fprintf(stderr, "ps: ccpu: %s\n", kvm_geterr(kd));
92 eval = rval = 1;
93 }
94 return(rval);
95}
96
97void
98nlisterr(nl)
99 struct nlist nl[];
100{
101 int i;
102
103 (void)fprintf(stderr, "ps: nlist: can't find following symbols:");
104 for (i = 0; nl[i].n_name != NULL; i++)
105 if (nl[i].n_value == 0)
106 (void)fprintf(stderr, " %s", nl[i].n_name);
107 (void)fprintf(stderr, "\n");
108}