pkg://procps-2.0.7-11.src.rpm:212926/procps-2.0.7-locale.patch
info downloads
--- procps-2.0.7/proc/sysinfo.c.jj Mon Jul 10 15:36:13 2000
+++ procps-2.0.7/proc/sysinfo.c Wed Jul 26 22:46:31 2000
@@ -58,13 +58,41 @@ static char buf[1024];
#define SET_IF_DESIRED(x,y) if(x) *(x) = (y) /* evals 'x' twice */
+/* /proc files are output in C locale, while we might be using
+ * some other locale. Make sure we parse double values with
+ * a "C" locale dot.
+ */
+#define ONE_DOUBLE(val, buf, failed) ({ \
+ double _d; \
+ char *_p, *_q; \
+ val = strtoul(buf, &_p, 10); \
+ if (_p == buf && *_p != '.') \
+ failed = 1; \
+ if (*_p == '.') { \
+ _p++; \
+ if (*_p >= '0' && *_p <= '9') { \
+ _d = strtoul(_p, &_q, 10); \
+ while (_p != _q) _d /= 10, _p++; \
+ if (val < 0) \
+ val -= _d; \
+ else \
+ val += _d; \
+ } \
+ } \
+ _p; })
+
/***********************************************************************/
int uptime(double *uptime_secs, double *idle_secs) {
double up=0, idle=0;
+ char *p;
+ int failed = 0;
FILE_TO_BUF(UPTIME_FILE,uptime_fd);
- if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
+ p = ONE_DOUBLE(up, buf, failed);
+ if (*p != ' ' && *p != '\t') failed = 1;
+ ONE_DOUBLE(idle, p, failed);
+ if (failed) {
fprintf(stderr, "bad data in " UPTIME_FILE "\n");
return 0;
}
@@ -107,9 +135,9 @@ static int init_Hertz_value(void){
unsigned long user_j, nice_j, sys_j, other_j; /* jiffies (clock ticks) */
double up_1, up_2, seconds;
unsigned long jiffies, h;
- int i = 0;
+ int i = 0, failed = 0;
do{
- FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_1);
+ FILE_TO_BUF(UPTIME_FILE,uptime_fd); ONE_DOUBLE(up_1, buf, failed);
/* uptime(&up_1, NULL); */
FILE_TO_BUF(STAT_FILE,stat_fd);
/* If we are SMP, then the first line is the sum of jiffies by all CPUs */
@@ -118,7 +146,7 @@ static int init_Hertz_value(void){
sscanf(buf, "cpu %lu %lu %lu %lu\n%n",
&user_j, &nice_j, &sys_j, &other_j, &i);
sscanf(buf+i, "cpu0 %lu %lu %lu %lu", &user_j, &nice_j, &sys_j, &other_j);
- FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_2);
+ FILE_TO_BUF(UPTIME_FILE,uptime_fd); ONE_DOUBLE(up_2, buf, failed);
/* uptime(&up_2, NULL); */
} while((long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */
jiffies = user_j + nice_j + sys_j + other_j;
@@ -171,9 +199,16 @@ int four_cpu_numbers(JT *uret, JT *nret,
/***********************************************************************/
int loadavg(double *av1, double *av5, double *av15) {
double avg_1=0, avg_5=0, avg_15=0;
+ char *p;
+ int failed = 0;
FILE_TO_BUF(LOADAVG_FILE,loadavg_fd);
- if (sscanf(buf, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) {
+ p = ONE_DOUBLE(avg_1, buf, failed);
+ if (*p != ' ' && *p != '\t') failed = 1;
+ p = ONE_DOUBLE(avg_5, p, failed);
+ if (*p != ' ' && *p != '\t') failed = 1;
+ ONE_DOUBLE(avg_15, p, failed);
+ if (failed) {
fprintf(stderr, "bad data in " LOADAVG_FILE "\n");
exit(1);
}
--- procps-2.0.7/top.c.jj Thu Jul 13 16:19:21 2000
+++ procps-2.0.7/top.c Wed Jul 26 22:56:27 2000
@@ -101,6 +101,8 @@
#include <setjmp.h>
#include <stdarg.h>
#include <sys/param.h>
+#include <locale.h>
+#include <langinfo.h>
#include "proc/sysinfo.h"
#include "proc/procps.h"
@@ -123,6 +125,7 @@ extern void register_sort_function (int
static int *cpu_mapping;
static int nr_cpu;
+static char *decimal_point;
/*#######################################################################
*#### Startup routines: parse_options, get_options, ##############
@@ -344,6 +347,7 @@ int main(int argc, char **argv)
struct sigaction sact;
setlocale(LC_ALL, "");
+ decimal_point = nl_langinfo(DECIMAL_POINT);
get_options();
/* set to PCPU sorting */
@@ -1423,12 +1427,12 @@ void do_stats(proc_t** p, float elapsed_
idle_ticks *= nr_cpu;
}
printf("CPU states:"
- " %2ld.%ld%% user, %2ld.%ld%% system,"
- " %2ld.%ld%% nice, %2ld.%ld%% idle",
- user_ticks / 10UL, user_ticks % 10UL,
- system_ticks / 10UL, system_ticks % 10UL,
- nice_ticks / 10UL, nice_ticks % 10UL,
- idle_ticks / 10UL, idle_ticks % 10UL);
+ " %2ld%s%ld%% user, %2ld%s%ld%% system,"
+ " %2ld%s%ld%% nice, %2ld%s%ld%% idle",
+ user_ticks / 10UL, decimal_point, user_ticks % 10UL,
+ system_ticks / 10UL, decimal_point, system_ticks % 10UL,
+ nice_ticks / 10UL, decimal_point, nice_ticks % 10UL,
+ idle_ticks / 10UL, decimal_point, idle_ticks % 10UL);
PUTP(top_clrtoeol);
putchar('\n');
}
@@ -1458,16 +1462,16 @@ void do_stats(proc_t** p, float elapsed_
+ i_ticks_o[i] + n_ticks_o[i]);
if (Irixmode) cpumap=i;
else cpumap=cpu_mapping[i];
- printf ("CPU%d states: %2d.%-d%% user, %2d.%-d%% system,"
- " %2d.%-d%% nice, %2d.%-d%% idle",
+ printf ("CPU%d states: %2d%s%-d%% user, %2d%s%-d%% system,"
+ " %2d%s%-d%% nice, %2d%s%-d%% idle",
cpumap,
- (u_ticks - u_ticks_o[i] + n_ticks - n_ticks_o[i]) * 100 / t_ticks,
+ (u_ticks - u_ticks_o[i] + n_ticks - n_ticks_o[i]) * 100 / t_ticks, decimal_point,
(u_ticks - u_ticks_o[i]) * 100 % t_ticks / 100,
- (s_ticks - s_ticks_o[i]) * 100 / t_ticks,
+ (s_ticks - s_ticks_o[i]) * 100 / t_ticks, decimal_point,
(s_ticks - s_ticks_o[i]) * 100 % t_ticks / 100,
- (n_ticks - n_ticks_o[i]) * 100 / t_ticks,
+ (n_ticks - n_ticks_o[i]) * 100 / t_ticks, decimal_point,
(n_ticks - n_ticks_o[i]) * 100 % t_ticks / 100,
- (i_ticks - i_ticks_o[i]) * 100 / t_ticks,
+ (i_ticks - i_ticks_o[i]) * 100 / t_ticks, decimal_point,
(i_ticks - i_ticks_o[i]) * 100 % t_ticks / 100);
s_ticks_o[i] = s_ticks;
u_ticks_o[i] = u_ticks;