[Xfce4-commits] <xfce4-cpufreq-plugin:master> Fix reading number of CPUs when cpufreq is available.
Harald Judt
noreply at xfce.org
Mon Aug 19 16:42:01 CEST 2013
Updating branch refs/heads/master
to e12661067a0e9d667573609926b0ecca92158931 (commit)
from 28e29670f4a9db924959503e7b36c2b67a42631b (commit)
commit e12661067a0e9d667573609926b0ecca92158931
Author: Harald Judt <h.judt at gmx.at>
Date: Mon Aug 19 16:37:42 2013 +0200
Fix reading number of CPUs when cpufreq is available.
When using cpufreq, the number of CPUs detected was wrong. Fix it by rewriting
the read_sysfs function.
panel-plugin/xfce4-cpufreq-linux.c | 37 +++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/panel-plugin/xfce4-cpufreq-linux.c b/panel-plugin/xfce4-cpufreq-linux.c
index 26ca1fd..585028b 100644
--- a/panel-plugin/xfce4-cpufreq-linux.c
+++ b/panel-plugin/xfce4-cpufreq-linux.c
@@ -325,26 +325,33 @@ cpufreq_cpu_read_procfs ()
return TRUE;
}
+static inline gboolean
+cpufreq_cpu_exists (gint num)
+{
+ const gchar *base = "/sys/devices/system/cpu";
+ gchar *file;
+ gboolean ret;
+
+ file = g_strdup_printf ("%s/cpu%d", base, num);
+ ret = g_file_test (file, G_FILE_TEST_EXISTS);
+ g_free (file);
+ return ret;
+}
+
static gboolean
-cpufreq_cpu_read_sysfs ()
+cpufreq_cpu_read_sysfs (void)
{
- gint j, i = -2;
- DIR *dir;
- struct dirent *dir_entry;
+ gchar *file;
+ gint count = 0, i = 0;
- if ((dir = opendir ("/sys/devices/system/cpu")) != NULL)
- {
- while ((dir_entry = readdir (dir)) != NULL)
- i++;
- }
- else
+ while (cpufreq_cpu_exists (count))
+ count++;
+
+ if (count == 0)
return FALSE;
- closedir (dir);
- for (j = 0; j < i; j++)
- {
- cpufreq_cpu_parse_sysfs_init (j, NULL);
- }
+ while (i < count)
+ cpufreq_cpu_parse_sysfs_init (i++, NULL);
return TRUE;
}
More information about the Xfce4-commits
mailing list