diff options
author | Steven Barth <steven@midlink.org> | 2009-07-10 13:33:48 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-07-10 13:33:48 +0000 |
commit | 223963e419e7dc0e660301050e6b42ee2a0002cb (patch) | |
tree | 6335722bd27d4bc55ee11d49692fac622599f574 /libs/sys | |
parent | 6ea0b5eb454457c3328ae002b3d32bb1555f5891 (diff) |
Optimise luci.sys
Diffstat (limited to 'libs/sys')
-rw-r--r-- | libs/sys/luasrc/sys.lua | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index c978fb70f..d6cc6346b 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -219,26 +219,14 @@ end -- @param bytes Number of bytes for the unique id -- @return String containing hex encoded id function uniqueid(bytes) - local fp = io.open("/dev/urandom") - local chunk = { fp:read(bytes):byte(1, bytes) } - fp:close() - - local hex = "" - - local pattern = "%02X" - for i, byte in ipairs(chunk) do - hex = hex .. pattern:format(byte) - end - - return hex + local rand = luci.fs.readfile("/dev/urandom", bytes) + return rand and nixio.bin.hexlify(rand) end --- Returns the current system uptime stats. -- @return String containing total uptime in seconds --- @return String containing idle time in seconds function uptime() - local loadavg = io.lines("/proc/uptime")() - return loadavg:match("^(.-) (.-)$") + return nixio.sysinfo().uptime end @@ -331,25 +319,43 @@ end --- Determine the names of available network interfaces. -- @return Table containing all current interface names function net.devices() - local devices = {} - for line in io.lines("/proc/net/dev") do - table.insert(devices, line:match(" *(.-):")) + local devs = {} + for k, v in ipairs(nixio.getifaddrs()) do + if v.family == "packet" then + devs[#devs+1] = v.name + end end - return devices + return devs end --- Return information about available network interfaces. -- @return Table containing all current interface names and their information function net.deviceinfo() - local devices = {} - for line in io.lines("/proc/net/dev") do - local name, data = line:match("^ *(.-): *(.*)$") - if name and data then - devices[name] = luci.util.split(data, " +", nil, true) + local devs = {} + for k, v in ipairs(nixio.getifaddrs()) do + if v.family == "packet" then + local d = v.data + d[1] = d.rx_bytes + d[2] = d.rx_packets + d[3] = d.rx_errors + d[4] = d.rx_dropped + d[5] = 0 + d[6] = 0 + d[7] = 0 + d[8] = d.multicast + d[9] = d.tx_bytes + d[10] = d.tx_packets + d[11] = d.tx_errors + d[12] = d.tx_dropped + d[13] = 0 + d[14] = d.collisions + d[15] = 0 + d[16] = 0 + devs[v.name] = d end end - return devices + return devs end |