fix printf warning
[oweals/busybox.git] / libbb / procps.c
index fcc9c2d3a907e7de50299c50bcb205e74fd37203..e405fb7efcc1ce5f3efd03b2701b11cfecdce610 100644 (file)
 
 #include "libbb.h"
 
-extern procps_status_t * procps_scan(int save_user_arg0)
+extern procps_status_t * procps_scan(int save_user_arg0
+#ifdef CONFIG_SELINUX
+       , int use_selinux , security_id_t *sid
+#endif
+       )
 {
        static DIR *dir;
        struct dirent *entry;
@@ -34,7 +38,7 @@ extern procps_status_t * procps_scan(int save_user_arg0)
        if (!dir) {
                dir = opendir("/proc");
                if(!dir)
-                       error_msg_and_die("Can't open /proc");
+                       bb_error_msg_and_die("Can't open /proc");
        }
        for(;;) {
                if((entry = readdir(dir)) == NULL) {
@@ -50,12 +54,22 @@ extern procps_status_t * procps_scan(int save_user_arg0)
                pid = atoi(name);
                curstatus.pid = pid;
 
+               sprintf(status, "/proc/%d", pid);
+               if(stat(status, &sb))
+                       continue;
+               my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
+
                sprintf(status, "/proc/%d/stat", pid);
                if((fp = fopen(status, "r")) == NULL)
                        continue;
-               if(fstat(fileno(fp), &sb))
-                       continue;
-               my_getpwuid(curstatus.user, sb.st_uid);
+#ifdef CONFIG_SELINUX
+               if(use_selinux)
+               {
+                       if(fstat_secure(fileno(fp), &sb, sid))
+                               continue;
+               }
+               else
+#endif
                name = fgets(buf, sizeof(buf), fp);
                fclose(fp);
                if(name == NULL)
@@ -103,10 +117,14 @@ extern procps_status_t * procps_scan(int save_user_arg0)
                else
                        curstatus.state[2] = ' ';
 
+#ifdef PAGE_SHIFT
                curstatus.rss <<= (PAGE_SHIFT - 10);     /* 2**10 = 1kb */
+#else
+               curstatus.rss *= (getpagesize() >> 10);     /* 2**10 = 1kb */
+#endif
 
-               sprintf(status, "/proc/%d/cmdline", pid);
                if(save_user_arg0) {
+                       sprintf(status, "/proc/%d/cmdline", pid);
                        if((fp = fopen(status, "r")) == NULL)
                                continue;
                        if((n=fread(buf, 1, sizeof(buf)-1, fp)) > 0) {