From 77f8d23a03609bb2a4224f6ed40500e11a472771 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Thu, 21 Jul 2022 22:48:12 -0400 Subject: [PATCH] ENH check that rapl interfaces are readable --- src/i_o.lua | 9 +++++++++ src/modules/filesystem.lua | 2 ++ src/modules/power.lua | 1 - src/sys.lua | 4 ++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/i_o.lua b/src/i_o.lua index 07bb153..1456793 100644 --- a/src/i_o.lua +++ b/src/i_o.lua @@ -88,10 +88,19 @@ M.file_exists = function(path) return M.exit_code_cmd('stat '..path..' > /dev/null 2>&1') == 0 end +M.file_readable = function(path) + return M.exit_code_cmd('test -r '..path) == 0 +end + M.assert_file_exists = function(path) M.assertf(M.file_exists(path), '%s does not exist', path) end +M.assert_file_readable = function(path) + M.assertf(M.file_exists(path), '%s does not exist', path) + M.assertf(M.file_readable(path), '%s is not readable', path) +end + -------------------------------------------------------------------------------- -- conky object execution diff --git a/src/modules/filesystem.lua b/src/modules/filesystem.lua index 4d18d56..5a27ffe 100644 --- a/src/modules/filesystem.lua +++ b/src/modules/filesystem.lua @@ -35,6 +35,8 @@ return function(config, main_state, common, width, point) local mk_bars = function(y) local paths = pure.map_keys('path', config.fs_paths) local names = pure.map_keys('name', config.fs_paths) + -- TODO this might not be enough (conky might actually need +x permissions + -- to decend into the dir and read its contents) impure.each(i_o.assert_file_exists, paths) local CONKY_CMDS = pure.map( pure.partial(string.format, '${fs_used_perc %s}', true), diff --git a/src/modules/power.lua b/src/modules/power.lua index d2e2e9e..c646454 100644 --- a/src/modules/power.lua +++ b/src/modules/power.lua @@ -110,7 +110,6 @@ return function(update_freq, config, common, width, point) point = point, width = width, set_state = nil, - -- TODO make sure these interfaces actually exist before trying to read them top = pure.concat( pure.map(mk_rate_blockspec, config.rapl_specs), {{mk_bat, config.battery ~= '', 0}} diff --git a/src/sys.lua b/src/sys.lua index 0f0cbce..4095960 100644 --- a/src/sys.lua +++ b/src/sys.lua @@ -84,7 +84,7 @@ local SYSFS_RAPL = '/sys/class/powercap' M.intel_powercap_reader = function(dev) local uj = __string_format('%s/%s/energy_uj', SYSFS_RAPL, dev) - i_o.assert_file_exists(uj) + i_o.assert_file_readable(uj) return function() return read_micro(uj) end @@ -97,7 +97,7 @@ local SYSFS_POWER = '/sys/class/power_supply' local format_power_path = function(battery, property) local p = __string_format('%s/%s/%s', SYSFS_POWER, battery, property) - i_o.assert_file_exists(p) + i_o.assert_file_readable(p) return p end