bin/78763: [PATCH] Added jail support to ps
Christopher Hodgins
christopher.hodgins at gmail.com
Sat Mar 12 20:00:12 PST 2005
>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 at 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:
More information about the freebsd-bugs
mailing list