aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/ps.c52
-rw-r--r--procps/top.c4
2 files changed, 29 insertions, 27 deletions
diff --git a/procps/ps.c b/procps/ps.c
index 0b603314d..18a6db36f 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -31,9 +31,7 @@
31#include <sys/ioctl.h> 31#include <sys/ioctl.h>
32#include "busybox.h" 32#include "busybox.h"
33#ifdef CONFIG_SELINUX 33#ifdef CONFIG_SELINUX
34#include <fs_secure.h> 34#include <selinux/selinux.h> /* for is_selinux_enabled() */
35#include <ss.h>
36#include <flask_util.h> /* for is_flask_enabled() */
37#endif 35#endif
38 36
39static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ 37static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */
@@ -48,8 +46,8 @@ extern int ps_main(int argc, char **argv)
48 46
49#ifdef CONFIG_SELINUX 47#ifdef CONFIG_SELINUX
50 int use_selinux = 0; 48 int use_selinux = 0;
51 security_id_t sid; 49 security_context_t sid=NULL;
52 if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") ) 50 if(is_selinux_enabled() && argv[1] && !strcmp(argv[1], "-c") )
53 use_selinux = 1; 51 use_selinux = 1;
54#endif 52#endif
55 53
@@ -58,34 +56,42 @@ extern int ps_main(int argc, char **argv)
58 terminal_width--; 56 terminal_width--;
59 57
60#ifdef CONFIG_SELINUX 58#ifdef CONFIG_SELINUX
61 if(use_selinux) 59 if (use_selinux)
62 printf(" PID Context Stat Command\n"); 60 printf(" PID Context Stat Command\n");
63 else 61 else
64#endif 62#endif
65 printf(" PID Uid VmSize Stat Command\n"); 63 printf(" PID Uid VmSize Stat Command\n");
66#ifdef CONFIG_SELINUX
67 while ((p = procps_scan(1, use_selinux, &sid)) != 0) {
68#else
69 while ((p = procps_scan(1)) != 0) {
70#endif
71 char *namecmd = p->cmd;
72 64
65 while ((p = procps_scan(1)) != 0) {
66 char *namecmd = p->cmd;
73#ifdef CONFIG_SELINUX 67#ifdef CONFIG_SELINUX
74 if(use_selinux) 68 if ( use_selinux )
75 { 69 {
76 char sbuf[128]; 70 char sbuf[128];
77 len = sizeof(sbuf); 71 len = sizeof(sbuf);
78 if(security_sid_to_context(sid, (security_context_t)&sbuf, &len))
79 strcpy(sbuf, "unknown");
80 72
73 if (is_selinux_enabled()) {
74 if (getpidcon(p->pid,&sid)<0)
75 sid=NULL;
76 }
77
78 if (sid) {
79 /* I assume sid initilized with NULL */
80 len = strlen(sid)+1;
81 safe_strncpy(sbuf, sid, len);
82 freecon(sid);
83 sid=NULL;
84 }else {
85 safe_strncpy(sbuf, "unknown",7);
86 }
81 len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); 87 len = printf("%5d %-32s %s ", p->pid, sbuf, p->state);
82 } 88 }
83 else 89 else
84#endif 90#endif
85 if(p->rss == 0) 91 if(p->rss == 0)
86 len = printf("%5d %-8s %s ", p->pid, p->user, p->state); 92 len = printf("%5d %-8s %s ", p->pid, p->user, p->state);
87 else 93 else
88 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); 94 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
89 i = terminal_width-len; 95 i = terminal_width-len;
90 96
91 if(namecmd != 0 && namecmd[0] != 0) { 97 if(namecmd != 0 && namecmd[0] != 0) {
diff --git a/procps/top.c b/procps/top.c
index c0f78f794..369a408d8 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -510,11 +510,7 @@ int top_main(int argc, char **argv)
510 /* read process IDs & status for all the processes */ 510 /* read process IDs & status for all the processes */
511 procps_status_t * p; 511 procps_status_t * p;
512 512
513#ifdef CONFIG_SELINUX
514 while ((p = procps_scan(0, 0, NULL) ) != 0) {
515#else
516 while ((p = procps_scan(0)) != 0) { 513 while ((p = procps_scan(0)) != 0) {
517#endif
518 int n = ntop; 514 int n = ntop;
519 515
520 top = xrealloc(top, (++ntop)*sizeof(procps_status_t)); 516 top = xrealloc(top, (++ntop)*sizeof(procps_status_t));