Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-4]: src/bin/ps pull up revs 1.29-1.31 from trunk (requested by ...
details: https://anonhg.NetBSD.org/src/rev/d25839944dd0
branches: netbsd-1-4
changeset: 469678:d25839944dd0
user: cgd <cgd%NetBSD.org@localhost>
date: Mon Nov 08 06:40:24 1999 +0000
description:
pull up revs 1.29-1.31 from trunk (requested by jdolecek):
When using the procfs for extracting process information, extract process
start time, arguments, and session leadership status. Also, fall back to
procfs when kvm_openfiles() completely fails (e.g. when /dev/mem is not
readable). Fixes PR#7772.
diffstat:
bin/ps/ps.c | 60 +++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 43 insertions(+), 17 deletions(-)
diffs (134 lines):
diff -r a175e32da4d4 -r d25839944dd0 bin/ps/ps.c
--- a/bin/ps/ps.c Mon Nov 08 06:40:19 1999 +0000
+++ b/bin/ps/ps.c Mon Nov 08 06:40:24 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ps.c,v 1.28 1999/03/27 21:38:08 bgrayson Exp $ */
+/* $NetBSD: ps.c,v 1.28.2.1 1999/11/08 06:40:24 cgd Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: ps.c,v 1.28 1999/03/27 21:38:08 bgrayson Exp $");
+__RCSID("$NetBSD: ps.c,v 1.28.2.1 1999/11/08 06:40:24 cgd Exp $");
#endif
#endif /* not lint */
@@ -86,10 +86,11 @@
int termwidth; /* width of screen (0 == infinity) */
int totwidth; /* calculated width of requested variables */
-int needuser, needcomm, needenv, commandonly;
+int needuser, needcomm, needenv, commandonly, use_procfs;
enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT;
+static KINFO *getkinfo_kvm __P((kvm_t *, int, int, int *, int));
static char *kludge_oldps_options __P((char *));
static int pscomp __P((const void *, const void *));
static void saveuser __P((KINFO *));
@@ -112,7 +113,6 @@
int argc;
char *argv[];
{
- struct kinfo_proc *kp;
struct varent *vent;
struct winsize ws;
gid_t egid = getegid();
@@ -305,8 +305,14 @@
(void)setegid(egid);
kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf);
- if (kd == 0)
- errx(1, "%s", errbuf);
+ if (kd == 0) {
+ if (dontuseprocfs)
+ errx(1, "%s", errbuf);
+ else {
+ warnx("kvm_openfiles: %s", errbuf);
+ fprintf(stderr, "ps: falling back to /proc-based lookup\n");
+ }
+ }
if (nlistf == NULL && memf == NULL && swapf == NULL)
(void)setgid(getgid());
@@ -319,10 +325,11 @@
* and adjusting header widths as appropiate.
*/
scanvars();
+
/*
* select procs
*/
- if ((kp = kvm_getprocs(kd, what, flag, &nentries)) == 0)
+ if (!kd || !(kinfo = getkinfo_kvm(kd, what, flag, &nentries, needuser)))
{
/* If/when the /proc-based code is ripped out
* again, make sure all references to the -K
@@ -339,28 +346,24 @@
* mounted) to grab as much information as we can.
* The guts of emulating kvm_getprocs() is in
* the file procfs_ops.c. */
- warnx("%s.", kvm_geterr(kd));
+ if (kd)
+ warnx("%s.", kvm_geterr(kd));
if (dontuseprocfs) {
exit(1);
}
/* procfs_getprocs supports all but the
* KERN_PROC_RUID flag. */
- kp=procfs_getprocs(what, flag, &nentries);
- if (kp == 0) {
+ kinfo = getkinfo_procfs(what, flag, &nentries);
+ if (kinfo == 0) {
errx(1, "fallback /proc-based lookup also failed. %s",
"Giving up...");
}
fprintf(stderr, "%s%s",
"Warning: /proc does not provide ",
"valid data for all fields.\n");
+ use_procfs = 1;
}
- if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL)
- err(1, "%s", "");
- for (i = nentries; --i >= 0; ++kp) {
- kinfo[i].ki_p = kp;
- if (needuser)
- saveuser(&kinfo[i]);
- }
+
/*
* print header
*/
@@ -396,6 +399,29 @@
/* NOTREACHED */
}
+static KINFO *
+getkinfo_kvm(kd, what, flag, nentriesp, needuser)
+ kvm_t *kd;
+ int what, flag, *nentriesp, needuser;
+{
+ struct kinfo_proc *kp;
+ KINFO *kinfo=NULL;
+ size_t i;
+
+ if ((kp = kvm_getprocs(kd, what, flag, nentriesp)) != 0)
+ {
+ if ((kinfo = malloc((*nentriesp) * sizeof(*kinfo))) == NULL)
+ err(1, "%s", "");
+ for (i = (*nentriesp); i-- > 0; kp++) {
+ kinfo[i].ki_p = kp;
+ if (needuser)
+ saveuser(&kinfo[i]);
+ }
+ }
+
+ return (kinfo);
+}
+
static void
scanvars()
{
Home |
Main Index |
Thread Index |
Old Index