last_patch95 from vodz:
[oweals/busybox.git] / procps / top.c
index 4204deaf2a6bae9c536fbeef3419d90528d8eece..2e1bd3286d38d324a874f0c10f668c249809a876 100644 (file)
@@ -155,11 +155,11 @@ static unsigned long Hertz;
 
 #define FILE_TO_BUF(filename, fd) do{                           \
     if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) {    \
-       perror_msg_and_die("/proc not be mounted?");            \
+       bb_perror_msg_and_die("/proc not be mounted?");            \
     }                                                           \
     lseek(fd, 0L, SEEK_SET);                                    \
     if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) {        \
-       perror_msg_and_die("%s", filename);                     \
+       bb_perror_msg_and_die("%s", filename);                     \
     }                                                           \
     buf[local_n] = '\0';                                        \
 }while(0)
@@ -167,7 +167,7 @@ static unsigned long Hertz;
 #define FILE_TO_BUF2(filename, fd) do{                          \
     lseek(fd, 0L, SEEK_SET);                                    \
     if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) {        \
-       perror_msg_and_die("%s", filename);                     \
+       bb_perror_msg_and_die("%s", filename);                     \
     }                                                           \
     buf[local_n] = '\0';                                        \
 }while(0)
@@ -313,19 +313,19 @@ static unsigned long display_generic(void)
        unsigned long total, used, mfree, shared, buffers, cached;
 
        /* read memory info */
-       fp = xfopen("meminfo", "r");
+       fp = bb_xfopen("meminfo", "r");
        fgets(buf, sizeof(buf), fp);    /* skip first line */
 
        if (fscanf(fp, "Mem: %lu %lu %lu %lu %lu %lu",
                   &total, &used, &mfree, &shared, &buffers, &cached) != 6) {
-               error_msg_and_die("failed to read '%s'", "meminfo");
+               bb_error_msg_and_die("failed to read '%s'", "meminfo");
        }
        fclose(fp);
        
        /* read load average */
-       fp = xfopen("loadavg", "r");
+       fp = bb_xfopen("loadavg", "r");
        if (fscanf(fp, "%f %f %f", &avg1, &avg2, &avg3) != 3) {
-               error_msg_and_die("failed to read '%s'", "loadavg");
+               bb_error_msg_and_die("failed to read '%s'", "loadavg");
        }
        fclose(fp);
 
@@ -447,7 +447,7 @@ int top_main(int argc, char **argv)
                    interval = atoi(optarg);
                    break;
                default:
-                   show_usage();
+                   bb_show_usage();
            }
        }
 
@@ -461,7 +461,7 @@ int top_main(int argc, char **argv)
 #endif
        /* change to /proc */
        if (chdir("/proc") < 0) {
-               perror_msg_and_die("chdir('/proc')");
+               bb_perror_msg_and_die("chdir('/proc')");
        }
 #if defined CONFIG_FEATURE_USE_TERMIOS
        tcgetattr(0, (void *) &initial_settings);
@@ -501,14 +501,18 @@ int top_main(int argc, char **argv)
                /* read process IDs & status for all the processes */
                procps_status_t * p;
 
+#ifdef CONFIG_SELINUX
+               while ((p = procps_scan(0, 0, NULL) ) != 0) {
+#else
                while ((p = procps_scan(0)) != 0) {
+#endif
                        int n = ntop;
 
                        top = xrealloc(top, (++ntop)*sizeof(procps_status_t));
                        memcpy(top + n, p, sizeof(procps_status_t));
                }
                if (ntop == 0) {
-               perror_msg_and_die("scandir('/proc')");
+               bb_perror_msg_and_die("scandir('/proc')");
        }
 #ifdef FEATURE_CPU_USAGE_PERCENTAGE
                if(!Hertz) {