entropy: widget rewritten, poolsize no longer an argument
This commit is contained in:
parent
493150c888
commit
d0aa48afb8
2
README
2
README
|
@ -229,8 +229,6 @@ vicious.widgets.gmail
|
|||
|
||||
vicious.widgets.entropy
|
||||
- provides available system entropy
|
||||
- takes the poolsize as an argument, or uses Linux 2.6 default
|
||||
entropy pool of 4096-bits
|
||||
- returns 1st value as available system entropy and 2nd value as
|
||||
available entropy in percent
|
||||
|
||||
|
|
17
entropy.lua
17
entropy.lua
|
@ -5,9 +5,9 @@
|
|||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local io = { open = io.open }
|
||||
local setmetatable = setmetatable
|
||||
local math = { ceil = math.ceil }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -16,15 +16,16 @@ module("vicious.entropy")
|
|||
|
||||
|
||||
-- {{{ Entropy widget type
|
||||
local function worker(format, poolsize)
|
||||
local function worker(format)
|
||||
local random = setmetatable(
|
||||
{ _path = "/proc/sys/kernel/random"},
|
||||
helpers.pathtotable
|
||||
)
|
||||
|
||||
-- Linux 2.6 has a default entropy pool of 4096-bits
|
||||
if poolsize == nil then poolsize = 4096 end
|
||||
|
||||
local poolsize = tonumber(random.poolsize)
|
||||
-- Get available entropy
|
||||
local f = io.open("/proc/sys/kernel/random/entropy_avail")
|
||||
local ent = tonumber(f:read("*line"))
|
||||
f:close()
|
||||
|
||||
local ent = tonumber(random.entropy_avail)
|
||||
-- Calculate percentage
|
||||
local ent_percent = math.ceil(ent * 100 / poolsize)
|
||||
|
||||
|
|
Loading…
Reference in New Issue