From 2f5a9b7661f483580f6e801ba050dc15f27e2721 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 13 Mar 2018 18:30:26 +0000 Subject: [PATCH] Add a "jail" keyword to list the name of a jail rather than its ID. Inspired by: mwlucas Reviewed by: jamie MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D14683 --- bin/ps/extern.h | 1 + bin/ps/keyword.c | 1 + bin/ps/print.c | 14 ++++++++++++++ bin/ps/ps.1 | 4 +++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/ps/extern.h b/bin/ps/extern.h index 4b760ec4c69d..dc58b1e9d00b 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -55,6 +55,7 @@ char *emulname(KINFO *, VARENT *); VARENT *find_varentry(VAR *); const char *fmt_argv(char **, char *, char *, size_t); double getpcpu(const KINFO *); +char *jailname(KINFO *, VARENT *); char *kvar(KINFO *, VARENT *); char *label(KINFO *, VARENT *); char *loginclass(KINFO *, VARENT *); diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 6842ad9e3a7b..fa8099f590d0 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -108,6 +108,7 @@ static VAR var[] = { {"inblk", "INBLK", NULL, "read-blocks", USER, rvar, ROFF(ru_inblock), LONG, "ld", 0}, {"inblock", "", "inblk", NULL, 0, NULL, 0, CHAR, NULL, 0}, + {"jail", "JAIL", NULL, "jail-name", LJUST, jailname, 0, CHAR, NULL, 0}, {"jid", "JID", NULL, "jail-id", 0, kvar, KOFF(ki_jid), INT, "d", 0}, {"jobc", "JOBC", NULL, "job-control-count", 0, kvar, KOFF(ki_jobc), SHORT, "d", 0}, diff --git a/bin/ps/print.c b/bin/ps/print.c index 437c1cbfc83a..c2853071b451 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -840,3 +841,16 @@ loginclass(KINFO *k, VARENT *ve __unused) } return (strdup(k->ki_p->ki_loginclass)); } + +char * +jailname(KINFO *k, VARENT *ve __unused) +{ + char *name; + + if (k->ki_p->ki_jid == 0) + return (strdup("-")); + name = jail_getname(k->ki_p->ki_jid); + if (name == NULL) + return (strdup("-")); + return (name); +} diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 5b298073a2df..9b119e75284d 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -29,7 +29,7 @@ .\" @(#)ps.1 8.3 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd January 23, 2018 +.Dd March 13, 2018 .Dt PS 1 .Os .Sh NAME @@ -576,6 +576,8 @@ group name (from egid) (alias .It Cm inblk total blocks read (alias .Cm inblock ) +.It Cm jail +jail name .It Cm jid jail ID .It Cm jobc