From owner-freebsd-bugs@FreeBSD.ORG Sun Mar 13 04:00:12 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 3A36116A4CF for ; Sun, 13 Mar 2005 04:00:12 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id F388B43D41 for ; Sun, 13 Mar 2005 04:00:11 +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 j2D40BFr002332 for ; Sun, 13 Mar 2005 04:00:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j2D40BOx002326; Sun, 13 Mar 2005 04:00:11 GMT (envelope-from gnats) Resent-Date: Sun, 13 Mar 2005 04:00:11 GMT Resent-Message-Id: <200503130400.j2D40BOx002326@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Christopher Hodgins Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C0CD716A4CF for ; Sun, 13 Mar 2005 03:59:49 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 96CFB43D1D for ; Sun, 13 Mar 2005 03:59:49 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j2D3xng2098514 for ; Sun, 13 Mar 2005 03:59:49 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j2D3xnMV098513; Sun, 13 Mar 2005 03:59:49 GMT (envelope-from nobody) Message-Id: <200503130359.j2D3xnMV098513@www.freebsd.org> Date: Sun, 13 Mar 2005 03:59:49 GMT From: Christopher Hodgins To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: bin/78763: [PATCH] Added jail support to ps X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Mar 2005 04:00:12 -0000 >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: