[uptime_freebsd] Deprecate synchronous sysctl

This commit is contained in:
mutlusun 2019-07-31 17:51:47 +02:00
parent df4048da37
commit 2b60a72d06
No known key found for this signature in database
GPG Key ID: C0AF8F434E1AB79B
4 changed files with 40 additions and 18 deletions

View File

@ -19,7 +19,7 @@ Fixed:
- Deprecate the use of `io.popen` in following widgets:
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd
* volume, gmail, mdir, mpd, fs
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
- [pkg,weather,contrib/btc] Allow function call without Awesome

View File

@ -21,7 +21,9 @@ local string = {
lower = string.lower,
format = string.format,
match = string.match,
find = string.find,
}
local table = { concat = table.concat }
local pcall = pcall
local assert = assert
local spawn = require("vicious.spawn")
@ -263,14 +265,22 @@ end
-- }}}
-- {{{ Return result from sysctl variable as table (async)
function helpers.sysctl_async(path, parse)
function helpers.sysctl_async(path_table, parse)
local ret = {}
local path = table.concat(path, " ")
local path = {}
spawn.with_line_callback("sysctl " .. helpers.shellquote(path), {
for i=1,#path_table do
path[i] = helpers.shellquote(path_table[i])
end
path = table.concat(path, " ")
spawn.with_line_callback("sysctl " .. path, {
stdout = function(line)
local key, value = string.match(line, "(.+): (.+)")
ret[key] = value
if not string.find(line, "sysctl: unknown oid") then
local key, value = string.match(line, "(.+): (.+)")
ret[key] = value
end
end,
output_done = function() parse(ret) end
})

View File

@ -13,10 +13,18 @@ function thermal_freebsd.async(format, warg, callback)
if not warg then return callback{} end
if type(warg) ~= "table" then warg = { warg } end
local thermals = {}
helpers.sysctl_async(warg, function(ret)
for i=1, #warg do
local thermals = {}
for k, v in pairs(ret) do
print(k, v)
end
for i=1,#warg do
print(warg[i])
print(ret[warg[i]])
print(ret["hw.acpi.thermal.tz0.temperature"])
print(ret['hw.acpi.thermal.tz0.temperature'])
if ret[warg[i]] ~= nil then
thermals[i] = string.match(ret[warg[i]], "[%d]+")
else

View File

@ -14,17 +14,21 @@ local uptime_freebsd = {}
-- {{{ Uptime widget type
local function worker(format)
local l1, l5, l15 = string.match(helpers.sysctl("vm.loadavg"), "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
local up_t = os.time() - tonumber(string.match(helpers.sysctl("kern.boottime"), "sec = ([%d]+)"))
function uptime_freebsd.async(format, warg, callback)
helpers.sysctl_async({ "vm.loadavg",
"kern.boottime" },
function(ret)
local l1, l5, l15 = string.match(ret["vm.loadavg"], "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
local up_t = os.time() - tonumber(string.match(ret["kern.boottime"], "sec = ([%d]+)"))
-- Get system uptime
local up_d = math.floor(up_t / (3600 * 24))
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
-- Get system uptime
local up_d = math.floor(up_t / (3600 * 24))
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
return {up_d, up_h, up_m, l1, l5, l15}
return callback({ up_d, up_h, up_m, l1, l5, l15 })
end)
end
-- }}}
return setmetatable(uptime_freebsd, { __call = function(_, ...) return worker(...) end })
return helpers.setasyncall(uptime_freebsd)