helpers: add sysctl helper for freebsd
This commit is contained in:
parent
3baade7b06
commit
78e1242601
38
helpers.lua
38
helpers.lua
|
@ -196,6 +196,44 @@ function helpers.scroll(text, maxlen, widget)
|
|||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Return result from one sysctl variable as string
|
||||
function helpers.sysctl(path)
|
||||
local fd = io.popen("sysctl -n " .. helpers.shellquote(path))
|
||||
|
||||
if not fd then
|
||||
return
|
||||
end
|
||||
|
||||
local ret = fd:read()
|
||||
|
||||
fd:close()
|
||||
|
||||
return ret
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Return result from multiple sysctl variables as table
|
||||
function helpers.sysctl_table(syspath)
|
||||
return setmetatable({ _path = syspath },
|
||||
{ __index = function(table, index)
|
||||
local path = "sysctl -n " .. helpers.shellquote(table._path .. "." .. index)
|
||||
local f = io.popen(path)
|
||||
if f then
|
||||
local s = f:read("*all")
|
||||
f:close()
|
||||
if select(2, s:gsub("\n", "\n")) > 1 then
|
||||
local o = { _path = path}
|
||||
setmetatable(o, getmetatable(table))
|
||||
return o
|
||||
else
|
||||
return s
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers
|
||||
|
||||
-- }}}
|
||||
|
|
Loading…
Reference in New Issue