From owner-freebsd-bugs@FreeBSD.ORG Sun Mar 13 06:00:19 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 42A9816A4CE for ; Sun, 13 Mar 2005 06:00:19 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0079E43D2D for ; Sun, 13 Mar 2005 06:00:19 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j2D60IRI024612 for ; Sun, 13 Mar 2005 06:00:18 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j2D60I0F024611; Sun, 13 Mar 2005 06:00:18 GMT (envelope-from gnats) Date: Sun, 13 Mar 2005 06:00:18 GMT Message-Id: <200503130600.j2D60I0F024611@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Chris Hodgins Subject: Re: bin/78763: [PATCH] Added jail support to ps X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Chris Hodgins List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Mar 2005 06:00:19 -0000 The following reply was made to PR bin/78763; it has been noted by GNATS. From: Chris Hodgins To: Christopher Hodgins Cc: freebsd-gnats-submit@freebsd.org Subject: Re: bin/78763: [PATCH] Added jail support to ps Date: Sun, 13 Mar 2005 06:01:37 +0000 Christopher Hodgins wrote: >>Number: 78763 >>Category: bin >>Synopsis: [PATCH] Added jail support to ps >>Confidential: no >>Severity: non-critical >>Priority: low >>Responsible: freebsd-bugs >>State: open >>Quarter: >>Keywords: >>Date-Required: >>Class: update >>Submitter-Id: current-users >>Arrival-Date: Sun Mar 13 04:00:11 GMT 2005 >>Closed-Date: >>Last-Modified: >>Originator: Christopher Hodgins >>Release: 5.4-PRERELEASE >>Organization: >>Environment: > > FreeBSD paranoia 5.4-PRERELEASE FreeBSD 5.4-PRERELEASE #0: Wed Mar 2 20:05:21 GMT 2005 root@paranoia:/usr/obj/usr/src/sys/paranoia i386 > > >>Description: > > These patches add jail support to ps through the -J jid option. > > This is my first patch so I would appreciate it if you could let me know if I have made any mistakes. > > Thanks > Chris > >>How-To-Repeat: > > >>Fix: > > --- ps.c.orig Sun Mar 13 02:43:25 2005 > +++ ps.c Sun Mar 13 02:55:06 2005 > @@ -129,6 +129,7 @@ > } l; > }; > > +static void attach_to_jail(const char *jailid); > static int check_procfs(void); > static int addelem_gid(struct listinfo *, const char *); > static int addelem_pid(struct listinfo *, const char *); > @@ -160,7 +161,7 @@ > "%cpu,%mem,command"; > static char Zfmt[] = "label"; > > -#define PS_ARGS "AaCce" OPT_LAZY_f "G:gHhjLlM:mN:O:o:p:rSTt:U:uvwXxZ" > +#define PS_ARGS "AaCce" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" > > int > main(int argc, char *argv[]) > @@ -209,6 +210,18 @@ > init_list(&ttylist, addelem_tty, sizeof(dev_t), "tty"); > init_list(&uidlist, addelem_uid, sizeof(uid_t), "user"); > memf = nlistf = _PATH_DEVNULL; > + > + /* > + * Must catch the Jail ID option first, so that all > + * of the other options run inside of the jail. > + */ > + if ((ch = getopt(argc, argv, "J:")) != -1) > + if (ch != '?') > + attach_to_jail(optarg); > + > + optind = 1; > + optreset = 1; > + > while ((ch = getopt(argc, argv, PS_ARGS)) != -1) > switch ((char)ch) { > case 'A': > @@ -265,6 +278,8 @@ > case 'h': > prtheader = ws.ws_row > 5 ? ws.ws_row : 22; > break; > + case 'J': > + break; > case 'j': > parsefmt(jfmt, 0); > _fmt = 1; > @@ -633,6 +648,20 @@ > exit(eval); > } > > +static void attach_to_jail(const char *jailid) { > +int jid = -1; > +char *ep; > + > + jid = strtol(jailid, &ep, 10); > + if (!jailid || *ep) { > + errx(1, "illegal jid: %s", jailid); > + optfatal = 1; > + } else if (jail_attach(jid) == -1) { > + err(1, "jail_attach(): %d", jid); > + optfatal = 1; > + } > +} > + > static int > addelem_gid(struct listinfo *inf, const char *elem) > { > @@ -1205,7 +1234,7 @@ > > (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", > "usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]", > - " [-M core] [-N system]", > + " [-J jid] [-M core] [-N system]", > " [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]", " ps [-L]"); > exit(1); > > > --- ps.1.orig Sun Mar 13 03:11:50 2005 > +++ ps.1 Sun Mar 13 03:11:32 2005 > @@ -140,6 +140,9 @@ > .It Fl h > Repeat the information header as often as necessary to guarantee one > header per page of information. > +.It Fl J > +Display information in the jail specified by > +.Cm jid . > .It Fl j > Print information associated with the following keywords: > .Cm user , pid , ppid , pgid , sid , jobc , state , tt , time , > > >>Release-Note: >>Audit-Trail: >>Unformatted: > The ps man page diff is missing the -J jid option from the argument list at the start. Here is the corrected diff: --- ps.1.orig Sun Mar 13 03:11:50 2005 +++ ps.1 Sun Mar 13 06:00:47 2005 @@ -40,6 +40,7 @@ .Op Fl aCcefHhjlmrSTuvwXxZ .Op Fl O Ar fmt | Fl o Ar fmt .Op Fl G Ar gid Ns Op , Ns Ar gid Ns Ar ... +.Op Fl J Ar jid .Op Fl M Ar core .Op Fl N Ar system .Op Fl p Ar pid Ns Op , Ns Ar pid Ns Ar ... @@ -140,6 +141,9 @@ .It Fl h Repeat the information header as often as necessary to guarantee one header per page of information. +.It Fl J +Display information in the jail specified by +.Cm jid . .It Fl j Print information associated with the following keywords: .Cm user , pid , ppid , pgid , sid , jobc , state , tt , time , Thanks Chris