1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
diff -Nur procps-3.2.8-orig/proc/sysinfo.c procps-3.2.8/proc/sysinfo.c
--- procps-3.2.8-orig/proc/sysinfo.c 2008-03-24 05:33:43.000000000 +0100
+++ procps-3.2.8/proc/sysinfo.c 2009-12-18 22:50:52.000000000 +0100
@@ -74,17 +74,19 @@
/***********************************************************************/
int uptime(double *restrict uptime_secs, double *restrict idle_secs) {
double up=0, idle=0;
- char *restrict savelocale;
+ char *savelocale;
FILE_TO_BUF(UPTIME_FILE,uptime_fd);
- savelocale = setlocale(LC_NUMERIC, NULL);
+ savelocale = strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC,"C");
if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
setlocale(LC_NUMERIC,savelocale);
+ free(savelocale);
fputs("bad data in " UPTIME_FILE "\n", stderr);
return 0;
}
setlocale(LC_NUMERIC,savelocale);
+ free(savelocale);
SET_IF_DESIRED(uptime_secs, up);
SET_IF_DESIRED(idle_secs, idle);
return up; /* assume never be zero seconds in practice */
@@ -128,9 +130,9 @@
double up_1, up_2, seconds;
unsigned long long jiffies;
unsigned h;
- char *restrict savelocale;
+ char *savelocale;
- savelocale = setlocale(LC_NUMERIC, NULL);
+ savelocale = strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "C");
do{
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_1);
@@ -141,6 +143,7 @@
/* uptime(&up_2, NULL); */
} while((long long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */
setlocale(LC_NUMERIC, savelocale);
+ free(savelocale);
jiffies = user_j + nice_j + sys_j + other_j;
seconds = (up_1 + up_2) / 2;
h = (unsigned)( (double)jiffies/seconds/smp_num_cpus );
@@ -303,16 +306,18 @@
/***********************************************************************/
void loadavg(double *restrict av1, double *restrict av5, double *restrict av15) {
double avg_1=0, avg_5=0, avg_15=0;
- char *restrict savelocale;
+ char *savelocale;
FILE_TO_BUF(LOADAVG_FILE,loadavg_fd);
- savelocale = setlocale(LC_NUMERIC, NULL);
+ savelocale = strdup(setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "C");
if (sscanf(buf, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) {
fputs("bad data in " LOADAVG_FILE "\n", stderr);
+ free(savelocale);
exit(1);
}
setlocale(LC_NUMERIC, savelocale);
+ free(savelocale);
SET_IF_DESIRED(av1, avg_1);
SET_IF_DESIRED(av5, avg_5);
SET_IF_DESIRED(av15, avg_15);
|