entropy: widget rewritten, poolsize no longer an argument

This commit is contained in:
Adrian C. (anrxc) 2009-11-11 03:56:43 +01:00
parent 493150c888
commit d0aa48afb8
2 changed files with 9 additions and 10 deletions

2
README
View File

@ -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

View File

@ -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)