diff -C 2 -r bin/ps.orig/ps.1 bin/ps/ps.1 *** bin/ps.orig/ps.1 Sat Nov 16 09:08:49 2002 --- bin/ps/ps.1 Wed Jan 22 20:18:26 2003 *************** *** 41,45 **** .Sh SYNOPSIS .Nm ! .Op Fl aCcefhjlmrSTuvwxZ .Op Fl M Ar core .Op Fl N Ar system --- 41,46 ---- .Sh SYNOPSIS .Nm ! .Op Fl aCcefHhjlmrSTuvwxZ ! .Op Fl J Ar jail .Op Fl M Ar core .Op Fl N Ar system *************** *** 99,105 **** --- 100,110 ---- Show commandline and environment information about swapped out processes. This option is honored only if the uid of the user is 0. + .It Fl H + When running jails only displays processes belonging to the host system. .It Fl h Repeat the information header as often as necessary to guarantee one header per page of information. + .It Fl J + Limit processes displayed to the jail specified. .It Fl j Print information associated with the following keywords: Only in bin/ps/: ps.1.orig Only in bin/ps/: ps.1.rej diff -C 2 -r bin/ps.orig/ps.c bin/ps/ps.c *** bin/ps.orig/ps.c Sat Nov 16 09:08:49 2002 --- bin/ps/ps.c Wed Jan 22 20:20:35 2003 *************** *** 101,104 **** --- 101,108 ---- static uid_t *getuids(const char *, int *); + static int getpidjail(pid_t, char*); + #define JAIL_BUFF_SIZE MAXHOSTNAMELEN + 2 + #define PROC_STATUS_PATH "/proc/%d/status" + static char dfmt[] = "pid,tt,state,time,command"; static char jfmt[] = "user,pid,ppid,pgid,jobc,state,tt,time,command"; *************** *** 113,119 **** #if defined(LAZY_PS) ! #define PS_ARGS "aCcefghjLlM:mN:O:o:p:rSTt:U:uvwxZ" #else ! #define PS_ARGS "aCceghjLlM:mN:O:o:p:rSTt:U:uvwxZ" #endif --- 117,123 ---- #if defined(LAZY_PS) ! #define PS_ARGS "aCcefgHhJ:jLlM:mN:O:o:p:rSTt:U:uvwxZ" #else ! #define PS_ARGS "aCcegHhJ:jLlM:mN:O:o:p:rSTt:U:uvwxZ" #endif *************** *** 127,130 **** --- 131,136 ---- pid_t pid; uid_t *uids; + char *jailName = NULL; /* Only show processes in this jail */ + int jailHost = 0; /* Only show processes in host system */ int all, ch, flag, i, _fmt, lineno, nentries, nocludge, dropgid; int prtheader, wflag, what, xflg, uid, nuids; *************** *** 193,196 **** --- 199,205 ---- prtheader = ws.ws_row > 5 ? ws.ws_row : 22; break; + case 'H': + jailHost = 1; + break; case 'j': parsefmt(jfmt); *************** *** 198,201 **** --- 207,213 ---- jfmt[0] = '\0'; break; + case 'J': + jailName = optarg; + break; case 'L': showkey(); *************** *** 387,390 **** --- 399,423 ---- */ for (i = lineno = 0; i < nentries; i++) { + + /* Nate: If limiting to jails in the host ... */ + if (jailHost) { + if(!(&kinfo[i])->ki_p || (&kinfo[i])->ki_p->ki_flag & P_JAILED) + continue; + } + + /* Nate: If limiting to a certain jail then check */ + else if (jailName) { + char pidjail[JAIL_BUFF_SIZE]; + + if(!(&kinfo[i])->ki_p || !((&kinfo[i])->ki_p->ki_flag & P_JAILED)) + continue; + + if(getpidjail((&kinfo[i])->ki_p->ki_pid, pidjail) < 0) + continue; + + if(strcmp(jailName, pidjail)) + continue; + } + if (xflg == 0 && ((&kinfo[i])->ki_p->ki_tdev == NODEV || ((&kinfo[i])->ki_p->ki_flag & P_CONTROLT ) == 0)) *************** *** 414,417 **** --- 447,494 ---- } + int + getpidjail(pid_t pid, char* buff) + { + int fd; + size_t bytes; + off_t off; + + /* Format the file name */ + if(snprintf(buff, JAIL_BUFF_SIZE, PROC_STATUS_PATH, pid)) + { + /* Open the file */ + if((fd = open(buff, O_RDONLY)) >= 0) + { + /* Seek to the last bit */ + off = lseek(fd, SEEK_END, 0); + + if(off != -1) + { + off -= JAIL_BUFF_SIZE; + if(off < 0) off = 0; + lseek(fd, SEEK_SET, off); + + if((bytes = read(fd, buff, JAIL_BUFF_SIZE - 1)) > 0) + { + /* Okay now jailname should be the last token */ + while(isspace(buff[bytes - 1])) + bytes--; + + buff[bytes] = 0; + + while(!isspace(buff[bytes - 1])) + bytes--; + + memmove(buff, buff + bytes, JAIL_BUFF_SIZE - bytes); + return 0; + + } + } + } + } + + return -1; + } + uid_t * getuids(const char *arg, int *nuids) *************** *** 652,656 **** (void)fprintf(stderr, "%s\n%s\n%s\n", ! "usage: ps [-aChjlmrSTuvwxZ] [-O|o fmt] [-p pid] [-t tty] [-U user]", " [-M core] [-N system]", " ps [-L]"); --- 729,733 ---- (void)fprintf(stderr, "%s\n%s\n%s\n", ! "usage: ps [-aCHhjlmrSTuvwxZ] [-J jail] [-O|o fmt] [-p pid] [-t tty] [-U user]", " [-M core] [-N system]", " ps [-L]");