diff options
Diffstat (limited to 'procps')
-rw-r--r-- | procps/free.c | 30 | ||||
-rw-r--r-- | procps/kill.c | 2 | ||||
-rw-r--r-- | procps/mpstat.c | 2 | ||||
-rw-r--r-- | procps/nmeter.c | 10 | ||||
-rw-r--r-- | procps/powertop.c | 4 | ||||
-rw-r--r-- | procps/pstree.c | 2 | ||||
-rw-r--r-- | procps/top.c | 7 |
7 files changed, 32 insertions, 25 deletions
diff --git a/procps/free.c b/procps/free.c index 3acfc4072..1e5d36742 100644 --- a/procps/free.c +++ b/procps/free.c | |||
@@ -44,6 +44,7 @@ struct globals { | |||
44 | #else | 44 | #else |
45 | # define G_unit_steps 10 | 45 | # define G_unit_steps 10 |
46 | #endif | 46 | #endif |
47 | unsigned long cached_kb, available_kb, reclaimable_kb; | ||
47 | }; | 48 | }; |
48 | /* Because of NOFORK, "globals" are not in global data */ | 49 | /* Because of NOFORK, "globals" are not in global data */ |
49 | 50 | ||
@@ -53,27 +54,30 @@ static unsigned long long scale(struct globals *g, unsigned long d) | |||
53 | } | 54 | } |
54 | 55 | ||
55 | /* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */ | 56 | /* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */ |
56 | static NOINLINE unsigned int parse_meminfo(unsigned long *cached_kb, unsigned long *available_kb) | 57 | static NOINLINE unsigned int parse_meminfo(struct globals *g) |
57 | { | 58 | { |
58 | char buf[60]; /* actual lines we expect are ~30 chars or less */ | 59 | char buf[60]; /* actual lines we expect are ~30 chars or less */ |
59 | FILE *fp; | 60 | FILE *fp; |
60 | int seen_cached_and_available; | 61 | int seen_cached_and_available_and_reclaimable; |
61 | 62 | ||
62 | fp = xfopen_for_read("/proc/meminfo"); | 63 | fp = xfopen_for_read("/proc/meminfo"); |
63 | *cached_kb = *available_kb = 0; | 64 | g->cached_kb = g->available_kb = g->reclaimable_kb = 0; |
64 | seen_cached_and_available = 2; | 65 | seen_cached_and_available_and_reclaimable = 3; |
65 | while (fgets(buf, sizeof(buf), fp)) { | 66 | while (fgets(buf, sizeof(buf), fp)) { |
66 | if (sscanf(buf, "Cached: %lu %*s\n", cached_kb) == 1) | 67 | if (sscanf(buf, "Cached: %lu %*s\n", &g->cached_kb) == 1) |
67 | if (--seen_cached_and_available == 0) | 68 | if (--seen_cached_and_available_and_reclaimable == 0) |
68 | break; | 69 | break; |
69 | if (sscanf(buf, "MemAvailable: %lu %*s\n", available_kb) == 1) | 70 | if (sscanf(buf, "MemAvailable: %lu %*s\n", &g->available_kb) == 1) |
70 | if (--seen_cached_and_available == 0) | 71 | if (--seen_cached_and_available_and_reclaimable == 0) |
72 | break; | ||
73 | if (sscanf(buf, "SReclaimable: %lu %*s\n", &g->reclaimable_kb) == 1) | ||
74 | if (--seen_cached_and_available_and_reclaimable == 0) | ||
71 | break; | 75 | break; |
72 | } | 76 | } |
73 | /* Have to close because of NOFORK */ | 77 | /* Have to close because of NOFORK */ |
74 | fclose(fp); | 78 | fclose(fp); |
75 | 79 | ||
76 | return seen_cached_and_available == 0; | 80 | return seen_cached_and_available_and_reclaimable == 0; |
77 | } | 81 | } |
78 | 82 | ||
79 | int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 83 | int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -82,7 +86,6 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
82 | struct globals G; | 86 | struct globals G; |
83 | struct sysinfo info; | 87 | struct sysinfo info; |
84 | unsigned long long cached, cached_plus_free, available; | 88 | unsigned long long cached, cached_plus_free, available; |
85 | unsigned long cached_kb, available_kb; | ||
86 | int seen_available; | 89 | int seen_available; |
87 | 90 | ||
88 | #if ENABLE_DESKTOP | 91 | #if ENABLE_DESKTOP |
@@ -118,10 +121,11 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
118 | /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ | 121 | /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ |
119 | G.mem_unit = (info.mem_unit ? info.mem_unit : 1); | 122 | G.mem_unit = (info.mem_unit ? info.mem_unit : 1); |
120 | /* Extract cached and memavailable from /proc/meminfo and convert to mem_units */ | 123 | /* Extract cached and memavailable from /proc/meminfo and convert to mem_units */ |
121 | seen_available = parse_meminfo(&cached_kb, &available_kb); | 124 | seen_available = parse_meminfo(&G); |
122 | available = ((unsigned long long) available_kb * 1024) / G.mem_unit; | 125 | available = ((unsigned long long) G.available_kb * 1024) / G.mem_unit; |
123 | cached = ((unsigned long long) cached_kb * 1024) / G.mem_unit; | 126 | cached = ((unsigned long long) G.cached_kb * 1024) / G.mem_unit; |
124 | cached += info.bufferram; | 127 | cached += info.bufferram; |
128 | cached += ((unsigned long long) G.reclaimable_kb * 1024) / G.mem_unit; | ||
125 | cached_plus_free = cached + info.freeram; | 129 | cached_plus_free = cached + info.freeram; |
126 | 130 | ||
127 | #define FIELDS_6 "%12llu %11llu %11llu %11llu %11llu %11llu\n" | 131 | #define FIELDS_6 "%12llu %11llu %11llu %11llu %11llu %11llu\n" |
diff --git a/procps/kill.c b/procps/kill.c index 073e74332..358d8f42b 100644 --- a/procps/kill.c +++ b/procps/kill.c | |||
@@ -270,7 +270,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv) | |||
270 | #if ENABLE_KILL || ENABLE_KILLALL | 270 | #if ENABLE_KILL || ENABLE_KILLALL |
271 | /* Pid or name is required for kill/killall */ | 271 | /* Pid or name is required for kill/killall */ |
272 | if (!arg) { | 272 | if (!arg) { |
273 | bb_error_msg("you need to specify whom to kill"); | 273 | bb_simple_error_msg("you need to specify whom to kill"); |
274 | return EXIT_FAILURE; | 274 | return EXIT_FAILURE; |
275 | } | 275 | } |
276 | 276 | ||
diff --git a/procps/mpstat.c b/procps/mpstat.c index e7dc4312a..3e07edc5c 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c | |||
@@ -931,7 +931,7 @@ int mpstat_main(int argc UNUSED_PARAM, char **argv) | |||
931 | /* Get CPU number */ | 931 | /* Get CPU number */ |
932 | unsigned n = xatoi_positive(t); | 932 | unsigned n = xatoi_positive(t); |
933 | if (n >= G.cpu_nr) | 933 | if (n >= G.cpu_nr) |
934 | bb_error_msg_and_die("not that many processors"); | 934 | bb_simple_error_msg_and_die("not that many processors"); |
935 | n++; | 935 | n++; |
936 | G.cpu_bitmap[n >> 3] |= 1 << (n & 7); | 936 | G.cpu_bitmap[n >> 3] |= 1 << (n & 7); |
937 | } | 937 | } |
diff --git a/procps/nmeter.c b/procps/nmeter.c index a01d19a6a..f0eb36740 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c | |||
@@ -351,7 +351,7 @@ static s_stat* init_cr(const char *param UNUSED_PARAM) | |||
351 | enum { CPU_FIELDCNT = 7 }; | 351 | enum { CPU_FIELDCNT = 7 }; |
352 | S_STAT(cpu_stat) | 352 | S_STAT(cpu_stat) |
353 | ullong old[CPU_FIELDCNT]; | 353 | ullong old[CPU_FIELDCNT]; |
354 | int bar_sz; | 354 | unsigned bar_sz; |
355 | char bar[1]; | 355 | char bar[1]; |
356 | S_STAT_END(cpu_stat) | 356 | S_STAT_END(cpu_stat) |
357 | 357 | ||
@@ -360,8 +360,8 @@ static void FAST_FUNC collect_cpu(cpu_stat *s) | |||
360 | ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 }; | 360 | ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 }; |
361 | unsigned frac[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 }; | 361 | unsigned frac[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 }; |
362 | ullong all = 0; | 362 | ullong all = 0; |
363 | int norm_all = 0; | 363 | unsigned norm_all = 0; |
364 | int bar_sz = s->bar_sz; | 364 | unsigned bar_sz = s->bar_sz; |
365 | char *bar = s->bar; | 365 | char *bar = s->bar; |
366 | int i; | 366 | int i; |
367 | 367 | ||
@@ -420,8 +420,8 @@ static s_stat* init_cpu(const char *param) | |||
420 | { | 420 | { |
421 | int sz; | 421 | int sz; |
422 | cpu_stat *s; | 422 | cpu_stat *s; |
423 | sz = strtoul(param, NULL, 0); /* param can be "" */ | 423 | sz = param[0] ? strtoul(param, NULL, 0) : 10; |
424 | if (sz < 10) sz = 10; | 424 | if (sz <= 0) sz = 1; |
425 | if (sz > 1000) sz = 1000; | 425 | if (sz > 1000) sz = 1000; |
426 | s = xzalloc(sizeof(*s) + sz); | 426 | s = xzalloc(sizeof(*s) + sz); |
427 | /*s->bar[sz] = '\0'; - xzalloc did it */ | 427 | /*s->bar[sz] = '\0'; - xzalloc did it */ |
diff --git a/procps/powertop.c b/procps/powertop.c index e70f5433b..d508b5f78 100644 --- a/procps/powertop.c +++ b/procps/powertop.c | |||
@@ -657,7 +657,7 @@ static void show_timerstats(void) | |||
657 | } | 657 | } |
658 | } else { | 658 | } else { |
659 | bb_putchar('\n'); | 659 | bb_putchar('\n'); |
660 | bb_error_msg("no stats available; run as root or" | 660 | bb_simple_error_msg("no stats available; run as root or" |
661 | " enable the timer_stats module"); | 661 | " enable the timer_stats module"); |
662 | } | 662 | } |
663 | } | 663 | } |
@@ -707,7 +707,7 @@ int powertop_main(int argc UNUSED_PARAM, char UNUSED_PARAM **argv) | |||
707 | 707 | ||
708 | /* Print warning when we don't have superuser privileges */ | 708 | /* Print warning when we don't have superuser privileges */ |
709 | if (geteuid() != 0) | 709 | if (geteuid() != 0) |
710 | bb_error_msg("run as root to collect enough information"); | 710 | bb_simple_error_msg("run as root to collect enough information"); |
711 | 711 | ||
712 | /* Get number of CPUs */ | 712 | /* Get number of CPUs */ |
713 | G.total_cpus = get_cpu_count(); | 713 | G.total_cpus = get_cpu_count(); |
diff --git a/procps/pstree.c b/procps/pstree.c index 1d124d2d2..67b711168 100644 --- a/procps/pstree.c +++ b/procps/pstree.c | |||
@@ -404,7 +404,7 @@ int pstree_main(int argc UNUSED_PARAM, char **argv) | |||
404 | else { | 404 | else { |
405 | dump_by_user(find_proc(1), uid); | 405 | dump_by_user(find_proc(1), uid); |
406 | if (!G.dumped) { | 406 | if (!G.dumped) { |
407 | bb_error_msg_and_die("no processes found"); | 407 | bb_simple_error_msg_and_die("no processes found"); |
408 | } | 408 | } |
409 | } | 409 | } |
410 | 410 | ||
diff --git a/procps/top.c b/procps/top.c index 89f9d23f4..5c41e8e10 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -979,6 +979,9 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval) | |||
979 | IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) | 979 | IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) |
980 | ) { | 980 | ) { |
981 | scan_mask ^= PSSCAN_TASKS; | 981 | scan_mask ^= PSSCAN_TASKS; |
982 | free(prev_hist); | ||
983 | prev_hist = NULL; | ||
984 | prev_hist_count = 0; | ||
982 | continue; | 985 | continue; |
983 | } | 986 | } |
984 | # endif | 987 | # endif |
@@ -1000,10 +1003,10 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval) | |||
1000 | # if ENABLE_FEATURE_TOPMEM | 1003 | # if ENABLE_FEATURE_TOPMEM |
1001 | if (c == 's') { | 1004 | if (c == 's') { |
1002 | scan_mask = TOPMEM_MASK; | 1005 | scan_mask = TOPMEM_MASK; |
1006 | sort_field = (sort_field + 1) % NUM_SORT_FIELD; | ||
1003 | free(prev_hist); | 1007 | free(prev_hist); |
1004 | prev_hist = NULL; | 1008 | prev_hist = NULL; |
1005 | prev_hist_count = 0; | 1009 | prev_hist_count = 0; |
1006 | sort_field = (sort_field + 1) % NUM_SORT_FIELD; | ||
1007 | continue; | 1010 | continue; |
1008 | } | 1011 | } |
1009 | # endif | 1012 | # endif |
@@ -1229,7 +1232,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1229 | #endif | 1232 | #endif |
1230 | } /* end of "while we read /proc" */ | 1233 | } /* end of "while we read /proc" */ |
1231 | if (ntop == 0) { | 1234 | if (ntop == 0) { |
1232 | bb_error_msg("no process info in /proc"); | 1235 | bb_simple_error_msg("no process info in /proc"); |
1233 | break; | 1236 | break; |
1234 | } | 1237 | } |
1235 | 1238 | ||