diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-12-11 00:16:50 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-12-11 00:16:50 +0000 |
commit | 4fd832da65e4abdcb67096960cfe64be43f7d304 (patch) | |
tree | 5eef462b645df216e17ea19c2d3a92a4f1adfcc8 | |
parent | 850a87bc6767cfe0b6460373a875a07dedb2ee5a (diff) |
Make ps understand -o cwd using the new KERN_PROC_CWD sysctl. Some help
and suggestions from guenther.
ok guenther
-rw-r--r-- | bin/ps/extern.h | 5 | ||||
-rw-r--r-- | bin/ps/keyword.c | 4 | ||||
-rw-r--r-- | bin/ps/nlist.c | 3 | ||||
-rw-r--r-- | bin/ps/print.c | 17 | ||||
-rw-r--r-- | bin/ps/ps.1 | 6 |
5 files changed, 27 insertions, 8 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h index 54561d24813..cc43314d707 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.14 2011/04/10 03:20:58 guenther Exp $ */ +/* $OpenBSD: extern.h,v 1.15 2011/12/11 00:16:49 nicm Exp $ */ /* $NetBSD: extern.h,v 1.10 1995/05/21 13:38:27 mycroft Exp $ */ /*- @@ -39,7 +39,7 @@ struct varent; extern fixpt_t ccpu; extern int eval, fscale, nlistread, rawcpu, maxslp; extern u_int mempages; -extern int sumrusage, termwidth, totwidth; +extern int sumrusage, termwidth, totwidth, kvm_sysctl_only; extern VAR var[]; extern VARENT *vhead; @@ -79,6 +79,7 @@ void tsize(const struct kinfo_proc *, VARENT *); void dsize(const struct kinfo_proc *, VARENT *); void ssize(const struct kinfo_proc *, VARENT *); void ucomm(const struct kinfo_proc *, VARENT *); +void curwd(const struct kinfo_proc *, VARENT *); void euname(const struct kinfo_proc *, VARENT *); void vsize(const struct kinfo_proc *, VARENT *); void wchan(const struct kinfo_proc *, VARENT *); diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 0b105b717e2..4653db0b790 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyword.c,v 1.32 2011/04/10 03:20:58 guenther Exp $ */ +/* $OpenBSD: keyword.c,v 1.33 2011/12/11 00:16:49 nicm Exp $ */ /* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */ /*- @@ -74,6 +74,7 @@ int utime(), stime(), ixrss(), idrss(), isrss(); { n1, n2, NULL, 0, fn, PIDLEN, 0, off, INT32, PIDFMT } #define USERLEN 8 +#define CWDLEN 40 /* Bit types must match their respective entries in struct kinfo_proc */ VAR var[] = { @@ -89,6 +90,7 @@ VAR var[] = { {"cpu", "CPU", NULL, 0, pvar, 3, 0, POFF(p_estcpu), UINT32, "d"}, {"cpuid", "CPUID", NULL, 0, pvar, 8, 0, POFF(p_cpuid), UINT64, "lld"}, {"cputime", "", "time"}, + {"cwd", "CWD", NULL, LJUST, curwd, CWDLEN}, {"dsiz", "DSIZ", NULL, 0, dsize, 4}, {"emul", "EMUL", NULL, LJUST, emulname, KI_EMULNAMELEN - 1}, {"etime", "", "start"}, diff --git a/bin/ps/nlist.c b/bin/ps/nlist.c index ba89a6ada1d..43aae25eaa8 100644 --- a/bin/ps/nlist.c +++ b/bin/ps/nlist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nlist.c,v 1.17 2009/10/27 23:59:22 deraadt Exp $ */ +/* $OpenBSD: nlist.c,v 1.18 2011/12/11 00:16:49 nicm Exp $ */ /* $NetBSD: nlist.c,v 1.11 1995/03/21 09:08:03 cgd Exp $ */ /*- @@ -65,7 +65,6 @@ int fscale; /* kernel _fscale variable */ int maxslp; extern kvm_t *kd; -extern int kvm_sysctl_only; #define kread(x, v) \ kvm_read(kd, psnl[x].n_value, &v, sizeof v) != sizeof(v) diff --git a/bin/ps/print.c b/bin/ps/print.c index 95d2cf7571a..2c3b84f19fd 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.50 2011/10/13 01:15:04 guenther Exp $ */ +/* $OpenBSD: print.c,v 1.51 2011/12/11 00:16:49 nicm Exp $ */ /* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */ /*- @@ -178,6 +178,21 @@ ucomm(const struct kinfo_proc *kp, VARENT *ve) } void +curwd(const struct kinfo_proc *kp, VARENT *ve) +{ + VAR *v; + int name[] = { CTL_KERN, KERN_PROC_CWD, kp->p_pid }; + char path[MAXPATHLEN]; + size_t pathlen = sizeof path; + + if (!kvm_sysctl_only || sysctl(name, 3, path, &pathlen, NULL, 0) != 0) + *path = '\0'; + + v = ve->var; + (void)printf("%-*s", v->width, path); +} + +void logname(const struct kinfo_proc *kp, VARENT *ve) { VAR *v; diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 4dcc9667321..7c61e09dd4f 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ps.1,v 1.78 2011/10/03 06:49:25 jmc Exp $ +.\" $OpenBSD: ps.1,v 1.79 2011/12/11 00:16:49 nicm Exp $ .\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1991, 1993, 1994 @@ -30,7 +30,7 @@ .\" .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: October 3 2011 $ +.Dd $Mdocdate: December 11 2011 $ .Dt PS 1 .Os .Sh NAME @@ -209,6 +209,8 @@ Command and arguments. Short-term CPU usage factor (for scheduling). .It Cm cpuid CPU ID (zero on single processor systems). +.It Cm cwd +Current working directory. .It Cm dsiz Data size, in Kilobytes. .It Cm emul |