Avoid decimal point localization in /proc/loadavg
Explicitly format the contents of /proc/loadavg to avoid the decimal point getting localized according to LC_NUMERIC. Using anything other than '.' is wrong and breaks top. Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
This commit is contained in:
parent
c47c9bdc1b
commit
c84697c259
|
@ -30,6 +30,7 @@ details. */
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include "cpuid.h"
|
#include "cpuid.h"
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define _COMPILING_NEWLIB
|
#define _COMPILING_NEWLIB
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -432,10 +433,14 @@ format_proc_loadavg (void *, char *&destbuf)
|
||||||
double loadavg[3] = { 0.0, 0.0, 0.0 };
|
double loadavg[3] = { 0.0, 0.0, 0.0 };
|
||||||
getloadavg (loadavg, 3);
|
getloadavg (loadavg, 3);
|
||||||
|
|
||||||
|
#define HUNDRETHS(l) (int)((l - floor(l))*100)
|
||||||
|
|
||||||
destbuf = (char *) crealloc_abort (destbuf, 48);
|
destbuf = (char *) crealloc_abort (destbuf, 48);
|
||||||
return sprintf (destbuf, "%.2f %.2f %.2f %u/%u\n",
|
return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u %u/%u\n",
|
||||||
loadavg[0], loadavg[1], loadavg[2], running,
|
(int)loadavg[0], HUNDRETHS(loadavg[0]),
|
||||||
(unsigned int)pids.npids);
|
(int)loadavg[1], HUNDRETHS(loadavg[1]),
|
||||||
|
(int)loadavg[2], HUNDRETHS(loadavg[2]),
|
||||||
|
running, (unsigned int)pids.npids);
|
||||||
}
|
}
|
||||||
|
|
||||||
static off_t
|
static off_t
|
||||||
|
|
Loading…
Reference in New Issue