ENH check that rapl interfaces are readable

This commit is contained in:
Nathan Dwarshuis 2022-07-21 22:48:12 -04:00
parent 7ea7c7cea5
commit 77f8d23a03
4 changed files with 13 additions and 3 deletions

View File

@ -88,10 +88,19 @@ M.file_exists = function(path)
return M.exit_code_cmd('stat '..path..' > /dev/null 2>&1') == 0 return M.exit_code_cmd('stat '..path..' > /dev/null 2>&1') == 0
end end
M.file_readable = function(path)
return M.exit_code_cmd('test -r '..path) == 0
end
M.assert_file_exists = function(path) M.assert_file_exists = function(path)
M.assertf(M.file_exists(path), '%s does not exist', path) M.assertf(M.file_exists(path), '%s does not exist', path)
end 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 -- conky object execution

View File

@ -35,6 +35,8 @@ return function(config, main_state, common, width, point)
local mk_bars = function(y) local mk_bars = function(y)
local paths = pure.map_keys('path', config.fs_paths) local paths = pure.map_keys('path', config.fs_paths)
local names = pure.map_keys('name', 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) impure.each(i_o.assert_file_exists, paths)
local CONKY_CMDS = pure.map( local CONKY_CMDS = pure.map(
pure.partial(string.format, '${fs_used_perc %s}', true), pure.partial(string.format, '${fs_used_perc %s}', true),

View File

@ -110,7 +110,6 @@ return function(update_freq, config, common, width, point)
point = point, point = point,
width = width, width = width,
set_state = nil, set_state = nil,
-- TODO make sure these interfaces actually exist before trying to read them
top = pure.concat( top = pure.concat(
pure.map(mk_rate_blockspec, config.rapl_specs), pure.map(mk_rate_blockspec, config.rapl_specs),
{{mk_bat, config.battery ~= '', 0}} {{mk_bat, config.battery ~= '', 0}}

View File

@ -84,7 +84,7 @@ local SYSFS_RAPL = '/sys/class/powercap'
M.intel_powercap_reader = function(dev) M.intel_powercap_reader = function(dev)
local uj = __string_format('%s/%s/energy_uj', SYSFS_RAPL, 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 function()
return read_micro(uj) return read_micro(uj)
end end
@ -97,7 +97,7 @@ local SYSFS_POWER = '/sys/class/power_supply'
local format_power_path = function(battery, property) local format_power_path = function(battery, property)
local p = __string_format('%s/%s/%s', SYSFS_POWER, 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 return p
end end