diff options
Diffstat (limited to 'srcx/jps.c')
-rw-r--r-- | srcx/jps.c | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -1,11 +1,16 @@ #include <sys/types.h> +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/user.h> + #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <kvm.h> #include <paths.h> +#include <limits.h> #include "util.h" @@ -14,8 +19,8 @@ #endif static void usage(); -static void printJailIds(); -static void runJailPs(int argc, char* argv[]); +static void print_jail_ids(); +static void run_jail_ps(int argc, char* argv[]); int main(int argc, char* argv[]) { @@ -23,11 +28,11 @@ int main(int argc, char* argv[]) int simple = 0; int jid = 0; - while((ch = getopt(argc, argv, "x")) != -1) + while((ch = getopt(argc, argv, "i")) != -1) { switch(ch) { - case 'x': + case 'i': simple = 1; break; @@ -48,7 +53,6 @@ int main(int argc, char* argv[]) errx(1, "can't run from inside jail"); /* Translate the jail name into an id if neccessary */ - name = argv[0]; jid = translate_jail_name(argv[0]); if(jid == -1) errx(1, "unknown jail host name: %s", argv[0]); @@ -79,13 +83,13 @@ int main(int argc, char* argv[]) static void usage() { - fprintf(stderr, "usage: jps [-x] jail [ ps_options ... ]\n"); + fprintf(stderr, "usage: jps [-i] jail [ ps_options ... ]\n"); exit(2); } static void run_jail_ps(int argc, char* argv[]) { - char* args[]; + char** args; int i; if(!check_jail_command(NULL, "/bin/ps")) @@ -97,7 +101,7 @@ static void run_jail_ps(int argc, char* argv[]) * then it could have replaced /bin/ps which we run... */ - args = alloca(sizeof(char*) * (argc + 2)); + args = (char**)alloca(sizeof(char*) * (argc + 2)); args[0] = "ps"; for(i = 0; i < argc; i++) @@ -105,18 +109,18 @@ static void run_jail_ps(int argc, char* argv[]) args[i + 1] = NULL; - run_jail_command(NULL, "/bin/ps", args, 0); + run_jail_command(NULL, "/bin/ps", args, JAIL_RUN_NOFORK); } static void print_jail_ids() { kvm_t* kd; + int nentries, i; struct kinfo_proc* kp; char errbuf[_POSIX2_LINE_MAX]; /* Open kernel interface */ - kd = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, _PATH_DEVNULL, - O_RDONLY, errbuf); + kd = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, errbuf); if(kd == NULL) errx(1, "couldn't connect to kernel: %s", errbuf); @@ -125,8 +129,12 @@ static void print_jail_ids() errx(1, "couldn't list processes: %s", kvm_geterr(kd)); for(i = 0; i < nentries; i++) - printf("%d ", (int)(kp[i].ki_pid)); + { + if(kp[i].ki_pid != getpid()) + printf("%d ", (int)(kp[i].ki_pid)); + } - fputc(stdout, '\n'); + fputc('\n', stdout); kvm_close(kd); } + |