aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/free.c36
-rw-r--r--procps/uptime.c3
2 files changed, 29 insertions, 10 deletions
diff --git a/procps/free.c b/procps/free.c
index a81189be9..997430b39 100644
--- a/procps/free.c
+++ b/procps/free.c
@@ -23,20 +23,36 @@
23 23
24#include "internal.h" 24#include "internal.h"
25#include <stdio.h> 25#include <stdio.h>
26#include <sys/sysinfo.h> 26#include <errno.h>
27
27 28
28#define DIVISOR 1024
29extern int free_main(int argc, char **argv) 29extern int free_main(int argc, char **argv)
30{ 30{
31 struct sysinfo info; 31 struct sysinfo info;
32 sysinfo(&info); 32 sysinfo(&info);
33 info.totalram/=DIVISOR; 33 /* Kernels prior to 2.4.x will return info.mem_unit==0. Kernels after
34 info.freeram/=DIVISOR; 34 * 2.4.x actually fill this value in */
35 info.totalswap/=DIVISOR; 35 if (info.mem_unit==0) {
36 info.freeswap/=DIVISOR; 36 /* Looks like we have a kernel prior to Linux 2.4.x */
37 info.sharedram/=DIVISOR; 37 info.mem_unit=1024;
38 info.bufferram/=DIVISOR; 38 info.totalram/=info.mem_unit;
39 39 info.freeram/=info.mem_unit;
40 info.totalswap/=info.mem_unit;
41 info.freeswap/=info.mem_unit;
42 info.sharedram/=info.mem_unit;
43 info.bufferram/=info.mem_unit;
44 } else {
45 /* Bah. Linux 2.4.x completely changed sysinfo. This can in theory
46 overflow a 32 bit unsigned long, but who puts more then 4GiB ram+swap
47 on an embedded system? */
48 info.mem_unit/=1024;
49 info.totalram*=info.mem_unit;
50 info.freeram*=info.mem_unit;
51 info.totalswap*=info.mem_unit;
52 info.freeswap*=info.mem_unit;
53 info.sharedram*=info.mem_unit;
54 info.bufferram*=info.mem_unit;
55 }
40 if (argc > 1 && **(argv + 1) == '-') { 56 if (argc > 1 && **(argv + 1) == '-') {
41 usage("free\n" 57 usage("free\n"
42#ifndef BB_FEATURE_TRIVIAL_HELP 58#ifndef BB_FEATURE_TRIVIAL_HELP
@@ -61,3 +77,5 @@ extern int free_main(int argc, char **argv)
61 info.freeram+info.freeswap); 77 info.freeram+info.freeswap);
62 return(TRUE); 78 return(TRUE);
63} 79}
80
81
diff --git a/procps/uptime.c b/procps/uptime.c
index 67ca34d75..efdbccf00 100644
--- a/procps/uptime.c
+++ b/procps/uptime.c
@@ -31,13 +31,14 @@
31#include "internal.h" 31#include "internal.h"
32#include <stdio.h> 32#include <stdio.h>
33#include <time.h> 33#include <time.h>
34#include <sys/sysinfo.h> 34#include <errno.h>
35 35
36#define FSHIFT 16 /* nr of bits of precision */ 36#define FSHIFT 16 /* nr of bits of precision */
37#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 37#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
38#define LOAD_INT(x) ((x) >> FSHIFT) 38#define LOAD_INT(x) ((x) >> FSHIFT)
39#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) 39#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
40 40
41
41extern int uptime_main(int argc, char **argv) 42extern int uptime_main(int argc, char **argv)
42{ 43{
43 int updays, uphours, upminutes; 44 int updays, uphours, upminutes;