Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/ps Use new sysctl/kvm interfaces. This will stop the "p...



details:   https://anonhg.NetBSD.org/src/rev/825f62378bc6
branches:  trunk
changeset: 486585:825f62378bc6
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri May 26 03:04:28 2000 +0000

description:
Use new sysctl/kvm interfaces.  This will stop the "proc size mismatch"
errors when internal kernel structures change size.  Also remove
the sgid bit - all live kernel data is accessed through the sysctl
interface.

diffstat:

 bin/ps/Makefile     |    4 +-
 bin/ps/extern.h     |   67 ++++++++--------
 bin/ps/keyword.c    |   57 ++++++-------
 bin/ps/nlist.c      |   45 ++++++++++-
 bin/ps/print.c      |  212 +++++++++++++++++++++------------------------------
 bin/ps/procfs_ops.c |   70 +++++++----------
 bin/ps/ps.c         |  144 ++++++++++-------------------------
 bin/ps/ps.h         |   24 +----
 8 files changed, 264 insertions(+), 359 deletions(-)

diffs (truncated from 1451 to 300 lines):

diff -r 4570b1611f31 -r 825f62378bc6 bin/ps/Makefile
--- a/bin/ps/Makefile   Fri May 26 02:44:33 2000 +0000
+++ b/bin/ps/Makefile   Fri May 26 03:04:28 2000 +0000
@@ -1,12 +1,10 @@
-#      $NetBSD: Makefile,v 1.26 1999/09/12 01:19:23 chs Exp $
+#      $NetBSD: Makefile,v 1.27 2000/05/26 03:04:28 simonb Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/2/93
 
 PROG=          ps
 SRCS=          fmt.c keyword.c nlist.c print.c ps.c procfs_ops.c
 DPADD=         ${LIBM} ${LIBKVM}
 LDADD=         -lm -lkvm
-BINGRP=                kmem
-BINMODE=       2555
 
 CWARNFLAGS+=   -Wno-format-y2k
 
diff -r 4570b1611f31 -r 825f62378bc6 bin/ps/extern.h
--- a/bin/ps/extern.h   Fri May 26 02:44:33 2000 +0000
+++ b/bin/ps/extern.h   Fri May 26 03:04:28 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.16 1999/12/03 02:26:36 simonb Exp $       */
+/*     $NetBSD: extern.h,v 1.17 2000/05/26 03:04:28 simonb Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -40,7 +40,7 @@
 struct var;
 struct varent;
 
-extern fixpt_t ccpu;
+extern double ccpu;
 extern int eval, fscale, mempages, nlistread, rawcpu;
 extern int sumrusage, termwidth, totwidth;
 extern int needenv, needcomm, commandonly, dontuseprocfs, use_procfs;
@@ -50,42 +50,43 @@
 extern VARENT *vhead;
 
 __BEGIN_DECLS
-void    command __P((KINFO *, VARENT *));
-void    cputime __P((KINFO *, VARENT *));
+void    command __P((struct kinfo_proc2 *, VARENT *));
+void    cputime __P((struct kinfo_proc2 *, VARENT *));
 int     donlist __P((void));
-void    evar __P((KINFO *, VARENT *));
+int     donlist_sysctl __P((void));
+void    evar __P((struct kinfo_proc2 *, VARENT *));
 void    fmt_puts __P((char *, int *));
 void    fmt_putc __P((int, int *));
-double  getpcpu __P((KINFO *));
-double  getpmem __P((KINFO *));
-void    logname __P((KINFO *, VARENT *));
-void    longtname __P((KINFO *, VARENT *));
-void    lstarted __P((KINFO *, VARENT *));
-void    maxrss __P((KINFO *, VARENT *));
+double  getpcpu __P((struct kinfo_proc2 *));
+double  getpmem __P((struct kinfo_proc2 *));
+void    logname __P((struct kinfo_proc2 *, VARENT *));
+void    longtname __P((struct kinfo_proc2 *, VARENT *));
+void    lstarted __P((struct kinfo_proc2 *, VARENT *));
+void    maxrss __P((struct kinfo_proc2 *, VARENT *));
 void    nlisterr __P((struct nlist *));
-void    p_rssize __P((KINFO *, VARENT *));
-void    pagein __P((KINFO *, VARENT *));
+void    p_rssize __P((struct kinfo_proc2 *, VARENT *));
+void    pagein __P((struct kinfo_proc2 *, VARENT *));
 void    parsefmt __P((char *));
-void    pcpu __P((KINFO *, VARENT *));
-void    pmem __P((KINFO *, VARENT *));
-void    pnice __P((KINFO *, VARENT *));
-void    pri __P((KINFO *, VARENT *));
+void    pcpu __P((struct kinfo_proc2 *, VARENT *));
+void    pmem __P((struct kinfo_proc2 *, VARENT *));
+void    pnice __P((struct kinfo_proc2 *, VARENT *));
+void    pri __P((struct kinfo_proc2 *, VARENT *));
 void    printheader __P((void));
-KINFO  *getkinfo_procfs __P((int, int, int*));
-char   **procfs_getargv __P((const struct kinfo_proc *, int));
-void    pvar __P((KINFO *, VARENT *));
-void    rssize __P((KINFO *, VARENT *));
-void    runame __P((KINFO *, VARENT *));
-void    rvar __P((KINFO *, VARENT *));
+struct kinfo_proc2
+       *getkinfo_procfs __P((int, int, int*));
+char   **procfs_getargv __P((const struct kinfo_proc2 *, int));
+void    pvar __P((struct kinfo_proc2 *, VARENT *));
+void    rssize __P((struct kinfo_proc2 *, VARENT *));
+void    runame __P((struct kinfo_proc2 *, VARENT *));
 void    showkey __P((void));
-void    started __P((KINFO *, VARENT *));
-void    state __P((KINFO *, VARENT *));
-void    tdev __P((KINFO *, VARENT *));
-void    tname __P((KINFO *, VARENT *));
-void    tsize __P((KINFO *, VARENT *));
-void    ucomm __P((KINFO *, VARENT *));
-void    uname __P((KINFO *, VARENT *));
-void    uvar __P((KINFO *, VARENT *));
-void    vsize __P((KINFO *, VARENT *));
-void    wchan __P((KINFO *, VARENT *));
+void    started __P((struct kinfo_proc2 *, VARENT *));
+void    state __P((struct kinfo_proc2 *, VARENT *));
+void    tdev __P((struct kinfo_proc2 *, VARENT *));
+void    tname __P((struct kinfo_proc2 *, VARENT *));
+void    tsize __P((struct kinfo_proc2 *, VARENT *));
+void    ucomm __P((struct kinfo_proc2 *, VARENT *));
+void    uname __P((struct kinfo_proc2 *, VARENT *));
+void    uvar __P((struct kinfo_proc2 *, VARENT *));
+void    vsize __P((struct kinfo_proc2 *, VARENT *));
+void    wchan __P((struct kinfo_proc2 *, VARENT *));
 __END_DECLS
diff -r 4570b1611f31 -r 825f62378bc6 bin/ps/keyword.c
--- a/bin/ps/keyword.c  Fri May 26 02:44:33 2000 +0000
+++ b/bin/ps/keyword.c  Fri May 26 03:04:28 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: keyword.c,v 1.22 2000/05/11 08:52:30 mjl Exp $ */
+/*     $NetBSD: keyword.c,v 1.23 2000/05/26 03:04:28 simonb Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)keyword.c  8.5 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: keyword.c,v 1.22 2000/05/11 08:52:30 mjl Exp $");
+__RCSID("$NetBSD: keyword.c,v 1.23 2000/05/26 03:04:28 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,10 +76,7 @@
 #endif
 
 /* Compute offset in common structures. */
-#define        POFF(x) offsetof(struct proc, x)
-#define        EOFF(x) offsetof(struct eproc, x)
-#define        UOFF(x) offsetof(struct usave, x)
-#define        ROFF(x) offsetof(struct rusage, x)
+#define        POFF(x) offsetof(struct kinfo_proc2, x)
 
 #define        UIDFMT  "u"
 #define        UIDLEN  5
@@ -108,9 +105,9 @@
        {"flags", "", "f"},
        {"holdcnt", "HOLDCNT", NULL, 0, pvar, 8, POFF(p_holdcnt), INT, "d"},
        {"ignored", "", "sigignore"},
-       {"inblk", "INBLK", NULL, USER, rvar, 4, ROFF(ru_inblock), LONG, "d"},
+       {"inblk", "INBLK", NULL, USER, pvar, 4, POFF(p_uru_inblock), LONG, "d"},
        {"inblock", "", "inblk"},
-       {"jobc", "JOBC", NULL, 0, evar, 4, EOFF(e_jobc), SHORT, "d"},
+       {"jobc", "JOBC", NULL, 0, evar, 4, POFF(p_jobc), SHORT, "d"},
        {"ktrace", "KTRACE", NULL, 0, pvar, 8, POFF(p_traceflag), INT, "x"},
        /* XXX */
        {"ktracep", "KTRACEP", NULL, 0, pvar, 8, POFF(p_tracep), KPTR, "x"},
@@ -118,44 +115,44 @@
        {"login", "LOGIN", NULL, LJUST, logname, MAXLOGNAME},
        {"logname", "", "login"},
        {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 28},
-       {"majflt", "MAJFLT", NULL, USER, rvar, 4, ROFF(ru_majflt), LONG, "d"},
-       {"minflt", "MINFLT", NULL, USER, rvar, 4, ROFF(ru_minflt), LONG, "d"},
-       {"msgrcv", "MSGRCV", NULL, USER, rvar, 4, ROFF(ru_msgrcv), LONG, "d"},
-       {"msgsnd", "MSGSND", NULL, USER, rvar, 4, ROFF(ru_msgsnd), LONG, "d"},
+       {"majflt", "MAJFLT", NULL, USER, pvar, 4, POFF(p_uru_majflt), LONG, "d"},
+       {"minflt", "MINFLT", NULL, USER, pvar, 4, POFF(p_uru_minflt), LONG, "d"},
+       {"msgrcv", "MSGRCV", NULL, USER, pvar, 4, POFF(p_uru_msgrcv), LONG, "d"},
+       {"msgsnd", "MSGSND", NULL, USER, pvar, 4, POFF(p_uru_msgsnd), LONG, "d"},
        {"ni", "", "nice"},
-       {"nice", "NI", NULL, 0, pnice, 2},
-       {"nivcsw", "NIVCSW", NULL, USER, rvar, 5, ROFF(ru_nivcsw), LONG, "d"},
+       {"nice", "NI", NULL, 0, pnice, 3},
+       {"nivcsw", "NIVCSW", NULL, USER, pvar, 5, POFF(p_uru_nivcsw), LONG, "d"},
        {"nsignals", "", "nsigs"},
-       {"nsigs", "NSIGS", NULL, USER, rvar, 4, ROFF(ru_nsignals), LONG, "d"},
-       {"nswap", "NSWAP", NULL, USER, rvar, 4, ROFF(ru_nswap), LONG, "d"},
-       {"nvcsw", "NVCSW", NULL, USER, rvar, 5, ROFF(ru_nvcsw), LONG, "d"},
+       {"nsigs", "NSIGS", NULL, USER, pvar, 4, POFF(p_uru_nsignals), LONG, "d"},
+       {"nswap", "NSWAP", NULL, USER, pvar, 4, POFF(p_uru_nswap), LONG, "d"},
+       {"nvcsw", "NVCSW", NULL, USER, pvar, 5, POFF(p_uru_nvcsw), LONG, "d"},
        /* XXX */
        {"nwchan", "WCHAN", NULL, 0, pvar, 6, POFF(p_wchan), KPTR, "x"},
-       {"oublk", "OUBLK", NULL, USER, rvar, 4, ROFF(ru_oublock), LONG, "d"},
+       {"oublk", "OUBLK", NULL, USER, pvar, 4, POFF(p_uru_oublock), LONG, "d"},
        {"oublock", "", "oublk"},
        /* XXX */
        {"p_ru", "P_RU", NULL, 0, pvar, 6, POFF(p_ru), KPTR, "x"},
        /* XXX */
-       {"paddr", "PADDR", NULL, 0, evar, 6, EOFF(e_paddr), KPTR, "x"},
+       {"paddr", "PADDR", NULL, 0, evar, 6, POFF(p_paddr), KPTR, "x"},
        {"pagein", "PAGEIN", NULL, USER, pagein, 6},
        {"pcpu", "", "%cpu"},
        {"pending", "", "sig"},
-       PID("pgid", "PGID", evar, EOFF(e_pgid)),
+       PID("pgid", "PGID", evar, POFF(p__pgid)),
        PID("pid", "PID", pvar, POFF(p_pid)),
        {"pmem", "", "%mem"},
-       PID("ppid", "PPID", evar, EOFF(e_ppid)),
+       PID("ppid", "PPID", evar, POFF(p_ppid)),
        {"pri", "PRI", NULL, 0, pri, 3},
        {"re", "RE", NULL, INF127, pvar, 3, POFF(p_swtime), UINT, "d"},
-       GID("rgid", "RGID", evar, EOFF(e_pcred.p_rgid)),
+       GID("rgid", "RGID", evar, POFF(p_rgid)),
        /* XXX */
        {"rlink", "RLINK", NULL, 0, pvar, 8, POFF(p_back), KPTR, "x"},
        {"rss", "RSS", NULL, 0, p_rssize, 4},
        {"rssize", "", "rsz"},
        {"rsz", "RSZ", NULL, 0, rssize, 4},
-       UID("ruid", "RUID", evar, EOFF(e_pcred.p_ruid)),
+       UID("ruid", "RUID", evar, POFF(p_ruid)),
        {"ruser", "RUSER", NULL, LJUST, runame, USERLEN},
-       {"sess", "SESS", NULL, 0, evar, 6, EOFF(e_sess), KPTR24, "x"},
-       PID("sid", "SID", evar, EOFF(e_sid)),
+       {"sess", "SESS", NULL, 0, evar, 6, POFF(p_sess), KPTR24, "x"},
+       PID("sid", "SID", evar, POFF(p_sid)),
        {"sig", "PENDING",
            NULL, 0, pvar, SIGWIDTH, POFF(p_siglist), SIGLIST, "s"},
        {"sigcatch", "CAUGHT",
@@ -168,17 +165,17 @@
        {"start", "STARTED", NULL, LJUST|USER, started, 8},
        {"stat", "", "state"},
        {"state", "STAT", NULL, 0, state, 4},
-       GID("svgid", "SVGID", evar, EOFF(e_pcred.p_svgid)),
-       UID("svuid", "SVUID", evar, EOFF(e_pcred.p_svuid)),
+       GID("svgid", "SVGID", evar, POFF(p_gid)),
+       UID("svuid", "SVUID", evar, POFF(p_uid)),
        {"tdev", "TDEV", NULL, 0, tdev, 4},
        {"time", "TIME", NULL, USER, cputime, 9},
-       PID("tpgid", "TGPID", evar, EOFF(e_tpgid)),
-       {"tsess", "TSESS", NULL, 0, evar, 6, EOFF(e_tsess), KPTR, "x"},
+       PID("tpgid", "TGPID", evar, POFF(p_tpgid)),
+       {"tsess", "TSESS", NULL, 0, evar, 6, POFF(p_tsess), KPTR, "x"},
        {"tsiz", "TSIZ", NULL, 0, tsize, 4},
        {"tt", "TT", NULL, LJUST, tname, 3},
        {"tty", "TTY", NULL, LJUST, longtname, 8},
        {"ucomm", "UCOMM", NULL, LJUST, ucomm, MAXCOMLEN},
-       UID("uid", "UID", evar, EOFF(e_ucred.cr_uid)),
+       UID("uid", "UID", evar, POFF(p_uid)),
        {"upr", "UPR", NULL, 0, pvar, 3, POFF(p_usrpri), UCHAR, "d"},
        {"user", "USER", NULL, LJUST, uname, USERLEN},
        {"usrpri", "", "upr"},
diff -r 4570b1611f31 -r 825f62378bc6 bin/ps/nlist.c
--- a/bin/ps/nlist.c    Fri May 26 02:44:33 2000 +0000
+++ b/bin/ps/nlist.c    Fri May 26 03:04:28 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nlist.c,v 1.15 1999/12/03 02:26:36 simonb Exp $        */
+/*     $NetBSD: nlist.c,v 1.16 2000/05/26 03:04:28 simonb Exp $        */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)nlist.c    8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: nlist.c,v 1.15 1999/12/03 02:26:36 simonb Exp $");
+__RCSID("$NetBSD: nlist.c,v 1.16 2000/05/26 03:04:28 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -46,10 +46,12 @@
 #include <sys/time.h>
 #include <sys/proc.h>
 #include <sys/resource.h>
+#include <sys/sysctl.h>
 
 #include <err.h>
 #include <errno.h>
 #include <kvm.h>
+#include <math.h>
 #include <nlist.h>
 #include <stdio.h>
 #include <string.h>
@@ -67,7 +69,7 @@
        { NULL }
 };
 
-fixpt_t        ccpu;                           /* kernel _ccpu variable */
+double ccpu;                           /* kernel _ccpu variable */
 int    nlistread;                      /* if nlist already read. */
 int    mempages;                       /* number of pages of phys. memory */
 int    fscale;                         /* kernel _fscale variable */
@@ -79,6 +81,7 @@
 donlist()
 {
        int rval;
+       fixpt_t xccpu;
 
        rval = 0;
        nlistread = 1;
@@ -95,13 +98,47 @@
                warnx("avail_start: %s", kvm_geterr(kd));
                eval = rval = 1;
        }
-       if (kread(X_CCPU, ccpu)) {
+       if (kread(X_CCPU, xccpu)) {
                warnx("ccpu: %s", kvm_geterr(kd));
                eval = rval = 1;
        }
+       ccpu = (double)xccpu / fscale;
        return (rval);
 }
 
+int
+donlist_sysctl()



Home | Main Index | Thread Index | Old Index