From af6435c9573821cbb9270a19d774f0160f568bf3 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 27 Aug 2005 09:49:09 +0000 Subject: [PATCH] smp support? git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@210 7f574dfc-610e-0410-a909-a81674777703 --- src/linux.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/linux.c b/src/linux.c index 5b2108c..b567bb5 100644 --- a/src/linux.c +++ b/src/linux.c @@ -361,7 +361,6 @@ void get_cpu_count() inline static void update_stat() { - // FIXME: arbitrary size? static struct cpu_info *cpu = NULL; char buf[256]; unsigned int i; @@ -374,21 +373,23 @@ inline static void update_stat() if (cpu == NULL) { cpu = malloc(info.cpu_count * sizeof(struct cpu_info)); } - if (stat_fp == NULL) + if (stat_fp == NULL) { stat_fp = open_file("/proc/stat", &rep); - else + } else { fseek(stat_fp, 0, SEEK_SET); - if (stat_fp == NULL) + } + if (stat_fp == NULL) { return; + } index = 0; - while (!feof(stat_fp) && index < info.cpu_count) { + while (!feof(stat_fp)) { if (fgets(buf, 255, stat_fp) == NULL) break; if (strncmp(buf, "procs_running ", 14) == 0) { sscanf(buf, "%*s %d", &info.run_procs); info.mask |= (1 << INFO_RUN_PROCS); - } else if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) { + } else if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3]) && index < info.cpu_count) { sscanf(buf, "%*s %u %u %u", &(cpu[index].cpu_user), &(cpu[index].cpu_nice), &(cpu[index].cpu_system)); index++; @@ -399,11 +400,13 @@ inline static void update_stat() for (index = 0; index < info.cpu_count; index++) { double delta; delta = current_update_time - last_update_time; - if (delta <= 0.001) + if (delta <= 0.001) { return; + } - if (cpu[index].clock_ticks == 0) + if (cpu[index].clock_ticks == 0) { cpu[index].clock_ticks = sysconf(_SC_CLK_TCK); + } curtmp = 0; cpu[index].cpu_val[0] = (cpu[index].cpu_user + cpu[index].cpu_nice + cpu[index].cpu_system - -- 1.7.9.5