aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--entropy.lua17
2 files changed, 9 insertions, 10 deletions
diff --git a/README b/README
index 1ebef10..d624545 100644
--- a/README
+++ b/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
diff --git a/entropy.lua b/entropy.lua
index ce87f84..e2f0e0c 100644
--- a/entropy.lua
+++ b/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)
- -- Linux 2.6 has a default entropy pool of 4096-bits
- if poolsize == nil then poolsize = 4096 end
+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
+ 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)