aboutsummaryrefslogtreecommitdiffstats
path: root/toolbox/ps.c
diff options
context:
space:
mode:
authorStephen Smalley <sds@tycho.nsa.gov>2012-01-13 08:53:56 -0500
committerStephen Smalley <sds@tycho.nsa.gov>2012-02-03 11:11:15 -0500
commit8290d1083ec7eee3f32265012f5d6be2774c4afc (patch)
tree6d7e239b2a5b3d4a8faf8c3f404f8d9b3270f61d /toolbox/ps.c
parent0458d373261d89979529853fa63cdd998b12e04a (diff)
downloadsystem_core-8290d1083ec7eee3f32265012f5d6be2774c4afc.tar.gz
system_core-8290d1083ec7eee3f32265012f5d6be2774c4afc.tar.bz2
system_core-8290d1083ec7eee3f32265012f5d6be2774c4afc.zip
Extend toolbox with SE Android support.
Add -Z option to ls and ps for displaying security contexts. Modify id to display security context. Add new SELinux commands: chcon, getenforce, getsebool, load_policy, restorecon, runcon, setenforce, setsebool. Change-Id: Ia20941be4a6cd706fe392fed6e38a37d880ec5f1
Diffstat (limited to 'toolbox/ps.c')
-rw-r--r--toolbox/ps.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 2aa3efb5..7c3de4a3 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -13,7 +13,6 @@
#include <cutils/sched_policy.h>
-
static char *nexttoksep(char **strp, char *sep)
{
char *p = strsep(strp,sep);
@@ -28,6 +27,7 @@ static char *nexttok(char **strp)
#define SHOW_TIME 2
#define SHOW_POLICY 4
#define SHOW_CPU 8
+#define SHOW_MACLABEL 16
static int display_flags = 0;
@@ -35,6 +35,7 @@ static int ps_line(int pid, int tid, char *namefilter)
{
char statline[1024];
char cmdline[1024];
+ char macline[1024];
char user[32];
struct stat stats;
int fd, r;
@@ -51,9 +52,11 @@ static int ps_line(int pid, int tid, char *namefilter)
if(tid) {
sprintf(statline, "/proc/%d/task/%d/stat", pid, tid);
cmdline[0] = 0;
+ snprintf(macline, sizeof(macline), "/proc/%d/task/%d/attr/current", pid, tid);
} else {
sprintf(statline, "/proc/%d/stat", pid);
- sprintf(cmdline, "/proc/%d/cmdline", pid);
+ sprintf(cmdline, "/proc/%d/cmdline", pid);
+ snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid);
fd = open(cmdline, O_RDONLY);
if(fd == 0) {
r = 0;
@@ -142,6 +145,19 @@ static int ps_line(int pid, int tid, char *namefilter)
}
if(!namefilter || !strncmp(name, namefilter, strlen(namefilter))) {
+ if (display_flags & SHOW_MACLABEL) {
+ fd = open(macline, O_RDONLY);
+ strcpy(macline, "-");
+ if (fd >= 0) {
+ r = read(fd, macline, sizeof(macline)-1);
+ close(fd);
+ if (r > 0)
+ macline[r] = 0;
+ }
+ printf("%-30s %-9s %-5d %-5d %s\n", macline, user, pid, ppid, cmdline[0] ? cmdline : name);
+ return 0;
+ }
+
printf("%-9s %-5d %-5d %-6d %-5d", user, pid, ppid, vss / 1024, rss * 4);
if (display_flags & SHOW_CPU)
printf(" %-2d", psr);
@@ -206,6 +222,8 @@ int ps_main(int argc, char **argv)
threads = 1;
} else if(!strcmp(argv[1],"-x")) {
display_flags |= SHOW_TIME;
+ } else if(!strcmp(argv[1], "-Z")) {
+ display_flags |= SHOW_MACLABEL;
} else if(!strcmp(argv[1],"-P")) {
display_flags |= SHOW_POLICY;
} else if(!strcmp(argv[1],"-p")) {
@@ -221,10 +239,14 @@ int ps_main(int argc, char **argv)
argv++;
}
- printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n",
- (display_flags&SHOW_CPU)?"CPU ":"",
- (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
- (display_flags&SHOW_POLICY)?"PCY " : "");
+ if (display_flags & SHOW_MACLABEL) {
+ printf("LABEL USER PID PPID NAME\n");
+ } else {
+ printf("USER PID PPID VSIZE RSS %s%s %s WCHAN PC NAME\n",
+ (display_flags&SHOW_CPU)?"CPU ":"",
+ (display_flags&SHOW_PRIO)?"PRIO NICE RTPRI SCHED ":"",
+ (display_flags&SHOW_POLICY)?"PCY " : "");
+ }
while((de = readdir(d)) != 0){
if(isdigit(de->d_name[0])){
int pid = atoi(de->d_name);