From 30db4bea7bd04df7d03edc31972f5da1f37887ad Mon Sep 17 00:00:00 2001 From: jinleileiking Date: Wed, 16 May 2012 18:37:15 +0200 Subject: cpufreq: handle not existing frequency/governer In some cases not all cpu informations will be provided. (ex. in virtual machines) Therefore default to "N/A". Signed-off-by: Adrian C. (anrxc) --- widgets/cpufreq.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'widgets') diff --git a/widgets/cpufreq.lua b/widgets/cpufreq.lua index a4f2eaa..11949da 100644 --- a/widgets/cpufreq.lua +++ b/widgets/cpufreq.lua @@ -29,13 +29,20 @@ local function worker(format, warg) } -- Default voltage values local voltage = { v = "N/A", mv = "N/A" } + local freqmhz = "N/A" + local freqghz = "N/A" -- Get the current frequency local freq = tonumber(cpufreq.scaling_cur_freq) -- Calculate MHz and GHz - local freqmhz = freq / 1000 - local freqghz = freqmhz / 1000 + + if freq then + freqmhz = freq / 1000 + freqghz = freqmhz / 1000 + end + + -- Get the current voltage if cpufreq.scaling_voltages then @@ -47,7 +54,7 @@ local function worker(format, warg) -- Get the current governor local governor = cpufreq.scaling_governor -- Represent the governor as a symbol - governor = governor_state[governor] or governor + governor = governor_state[governor] or governor or "N/A" return {freqmhz, freqghz, voltage.mv, voltage.v, governor} end -- cgit v1.2.3