diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2017-01-30 16:27:22 +0100 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2017-02-06 23:43:46 +0100 |
commit | ccae0b18fc908f6956626ca26ba19663140ebaa3 (patch) | |
tree | 801366dabe360cc9ce848f49a62e4c06f33cda60 | |
parent | 5b76d21caf636ec2cb88f036e39fd20fb414cb4f (diff) |
rsmemsiz: Use sysinfo to obtain uptime.
Now that uptime() is only used to obtain the load average it's trivial to
replace.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | rose/rsmemsiz.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/rose/rsmemsiz.c b/rose/rsmemsiz.c index 1d409ae..b2ad0da 100644 --- a/rose/rsmemsiz.c +++ b/rose/rsmemsiz.c @@ -5,6 +5,7 @@ #include <ctype.h> #include <unistd.h> #include <time.h> +#include <sys/sysinfo.h> #include <sys/utsname.h> #include <sys/types.h> #include <sys/stat.h> @@ -50,17 +51,16 @@ static char buf[300]; #define SET_IF_DESIRED(x,y) if (x) *(x) = (y) /* evals 'x' twice */ -static int uptime(double *uptime_secs) +static int getuptime(double *uptime_secs) { - double up=0; + struct sysinfo si; + + if (sysinfo(&si) < 0) + return -1; + + *uptime_secs = si.uptime; - FILE_TO_BUF(PROC_UPTIME_FILE) - if (sscanf(buf, "%lf %*f", &up) < 1) { - fprintf(stdout, "ERROR: Bad data in %s\r", PROC_UPTIME_FILE); return 0; - } - SET_IF_DESIRED(uptime_secs, up); - return up; /* assume never be zero seconds in practice */ } /* The following /proc/meminfo parsing routine assumes the following format: @@ -140,7 +140,7 @@ int main(int argc, char **argv) } /* read and calculate the amount of uptime and format it nicely */ - uptime(&uptime_secs); + getuptime(&uptime_secs); updays = (int) uptime_secs / (60*60*24); upminutes = (int) uptime_secs / 60; uphours = upminutes / 60; |