From owner-freebsd-bugs@FreeBSD.ORG Sun Mar 13 05:50:03 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 3416C16A4CF for ; Sun, 13 Mar 2005 05:50:03 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E6D4443D41 for ; Sun, 13 Mar 2005 05:50:02 +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 j2D5o2pK023333 for ; Sun, 13 Mar 2005 05:50:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j2D5o2TT023332; Sun, 13 Mar 2005 05:50:02 GMT (envelope-from gnats) Resent-Date: Sun, 13 Mar 2005 05:50:02 GMT Resent-Message-Id: <200503130550.j2D5o2TT023332@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 28BAD16A4CE for ; Sun, 13 Mar 2005 05:41:09 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id DB8C243D1D for ; Sun, 13 Mar 2005 05:41:08 +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 j2D5f8xF036248 for ; Sun, 13 Mar 2005 05:41:08 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j2D5f8VV036247; Sun, 13 Mar 2005 05:41:08 GMT (envelope-from nobody) Message-Id: <200503130541.j2D5f8VV036247@www.freebsd.org> Date: Sun, 13 Mar 2005 05:41:08 GMT From: Christopher Hodgins To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: bin/78768: [Patch] Added jail support to top 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 05:50:03 -0000 >Number: 78768 >Category: bin >Synopsis: [Patch] Added jail support to top >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 05:50:02 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 top through the -j jid option. This is my second patch so I would appreciate it if you could let me know if I have made any mistakes. Thanks Chris >How-To-Repeat: N/A >Fix: --- top.c.orig Sun Mar 13 05:32:21 2005 +++ top.c Sun Mar 13 03:55:12 2005 @@ -39,6 +39,7 @@ #include #include #include +#include /* includes specific to top */ #include "display.h" /* interface to display package */ @@ -137,6 +138,8 @@ int (*d_header)() = i_header; int (*d_process)() = i_process; +/* non-display routines that need to be pre-declared */ +static int attach_to_jail(const char *jailid); main(argc, argv) @@ -275,7 +278,23 @@ optind = 1; } - while ((i = getopt(ac, av, "SIHbinquvs:d:U:m:o:t")) != EOF) + /* + * Must catch the Jail ID option first, so that all + * of the other options run inside of the jail. + */ + opterr = 0; + if ((ch = getopt(argc, argv, "j:")) != -1) { + if (ch != '?') { + if (attach_to_jail(optarg) == -1) + exit(1); + } + } + + opterr = 1; + optind = 1; + optreset = 1; + + while ((i = getopt(ac, av, "SIHbinquvs:d:U:m:o:tj:")) != EOF) { switch(i) { @@ -387,11 +406,14 @@ case 'H': ps.thread = !ps.thread; break; + + case 'j': + break; default: fprintf(stderr, "\ Top version %s\n\ -Usage: %s [-HISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n", +Usage: %s [-HISbinqut] [-j jid] [-d x] [-s x] [-o field] [-U username] [number]\n", version_string(), myname); exit(1); } @@ -1045,6 +1067,21 @@ #endif quit(0); /*NOTREACHED*/ +} + +static int 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); + return (-1); + } else if (jail_attach(jid) == -1) { + err(1, "jail_attach(): %d", jid); + return (-1); + } + return (0); } /* --- top.1.orig Sun Mar 13 05:33:04 2005 +++ top.1 Sun Mar 13 05:37:26 2005 @@ -12,6 +12,8 @@ [ .B \-SbiInqutv ] [ +.BI \-j jid +] [ .BI \-d count ] [ .BI \-s time @@ -143,6 +145,10 @@ .IR username . This option currently only accepts usernames and will not understand uid numbers. +.TP +.BI \-j jid +Show only those processes in jail +.IR jid . .PP Both .I count >Release-Note: >Audit-Trail: >Unformatted: