mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 04:17:33 +00:00
some fixes for update_stat():
- initialize cpu_info struct properly (a large conkyrc could pollute that memory area) - allocate info.cpu_usage to cpu_count + 1 git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@220 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
2c8acab933
commit
0727d1e50d
12
src/linux.c
12
src/linux.c
@ -320,13 +320,14 @@ void update_total_processes()
|
|||||||
update_sysinfo();
|
update_sysinfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CPU_SAMPLE_COUNT 15
|
||||||
struct cpu_info {
|
struct cpu_info {
|
||||||
unsigned int cpu_user;
|
unsigned int cpu_user;
|
||||||
unsigned int cpu_system;
|
unsigned int cpu_system;
|
||||||
unsigned int cpu_nice;
|
unsigned int cpu_nice;
|
||||||
double last_cpu_sum;
|
double last_cpu_sum;
|
||||||
int clock_ticks;
|
int clock_ticks;
|
||||||
double cpu_val[15];
|
double cpu_val[CPU_SAMPLE_COUNT];
|
||||||
};
|
};
|
||||||
static short cpu_setup = 0;
|
static short cpu_setup = 0;
|
||||||
static int rep;
|
static int rep;
|
||||||
@ -354,7 +355,7 @@ void get_cpu_count()
|
|||||||
info.cpu_count++;
|
info.cpu_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.cpu_usage = malloc(info.cpu_count * sizeof(float));
|
info.cpu_usage = malloc((info.cpu_count + 1) * sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -371,6 +372,13 @@ inline static void update_stat()
|
|||||||
}
|
}
|
||||||
if (cpu == NULL) {
|
if (cpu == NULL) {
|
||||||
cpu = malloc((info.cpu_count + 1) * sizeof(struct cpu_info));
|
cpu = malloc((info.cpu_count + 1) * sizeof(struct cpu_info));
|
||||||
|
for (index = 0; index < info.cpu_count + 1; ++index) {
|
||||||
|
cpu[index].clock_ticks = 0;
|
||||||
|
cpu[index].last_cpu_sum = 0;
|
||||||
|
for (i = 0; i < CPU_SAMPLE_COUNT; ++i) {
|
||||||
|
cpu[index].cpu_val[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (stat_fp == NULL) {
|
if (stat_fp == NULL) {
|
||||||
stat_fp = open_file("/proc/stat", &rep);
|
stat_fp = open_file("/proc/stat", &rep);
|
||||||
|
Loading…
Reference in New Issue
Block a user