From nobody@FreeBSD.org  Sun Mar 13 05:41:09 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 28BAD16A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <christopher.hodgins@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [Patch] Added jail support to top
X-Send-Pr-Version: www-2.3

>Number:         78768
>Category:       bin
>Synopsis:       [patch] [jail] Added jail support to top(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 13 05:50:02 GMT 2005
>Closed-Date:    Sat Sep 27 03:54:02 UTC 2008
>Last-Modified:  Sat Sep 27 03:54:02 UTC 2008
>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 <setjmp.h>
 #include <ctype.h>
 #include <sys/time.h>
+#include <unistd.h>

 /* 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:
Responsible-Changed-From-To: freebsd-bugs->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: Tue Mar 15 22:17:34 GMT 2005 
Responsible-Changed-Why:  
I'm working in this area, so I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78768 

From: Mateusz Guzik <mjguzik@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: bin/78768: [patch] [jail] Added jail support to top(1)
Date: Sun, 6 Jul 2008 21:54:38 +0200

 This PR can be closed, jids in top are supported starting from FreeBSD 6.3.

From: Pawel Jakub Dawidek <pjd@FreeBSD.org>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/78768: [patch] [jail] Added jail support to top(1)
Date: Mon, 7 Jul 2008 10:43:14 +0200

 --GxcwvYAGnODwn7V8
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Sun, Jul 06, 2008 at 08:20:03PM +0000, Mateusz Guzik wrote:
 > The following reply was made to PR bin/78768; it has been noted by GNATS.
 >=20
 > From: Mateusz Guzik <mjguzik@gmail.com>
 > To: bug-followup@FreeBSD.org
 > Cc: =20
 > Subject: bin/78768: [patch] [jail] Added jail support to top(1)
 > Date: Sun, 6 Jul 2008 21:54:38 +0200
 >=20
 >  This PR can be closed, jids in top are supported starting from FreeBSD 6=
 .3.
 
 There is no option to filter process list by JID. Such functionality is
 implemented only for pgrep(1).
 
 --=20
 Pawel Jakub Dawidek                       http://www.wheel.pl
 pjd@FreeBSD.org                           http://www.FreeBSD.org
 FreeBSD committer                         Am I Evil? Yes, I Am!
 
 --GxcwvYAGnODwn7V8
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.4 (FreeBSD)
 
 iD8DBQFIcdchForvXbEpPzQRAvvsAJ0aeKDAI1+eNNsY9QSgZaPOVn4hNQCdH0ly
 ON/akQ+VsP/cTXF5KwqFHK4=
 =DN3Y
 -----END PGP SIGNATURE-----
 
 --GxcwvYAGnODwn7V8--
Responsible-Changed-From-To: pjd->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Sep 25 15:44:43 UTC 2008 
Responsible-Changed-Why:  
I will see if this can be added for the upgrade to 3.8b1 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78768 
State-Changed-From-To: open->closed 
State-Changed-By: edwin 
State-Changed-When: Sat Sep 27 03:52:50 UTC 2008 
State-Changed-Why:  
This has been implemnted in the upcoming 3.8b1 update.  

http://www.freebsd.org/cgi/query-pr.cgi?pr=78768 
>Unformatted:
