ENH make interface finder more robust
This commit is contained in:
parent
62008e7eb7
commit
e5f5e54eec
14
src/sys.lua
14
src/sys.lua
|
@ -151,20 +151,20 @@ end
|
||||||
|
|
||||||
-- ASSUME realpath exists (part of coreutils)
|
-- ASSUME realpath exists (part of coreutils)
|
||||||
|
|
||||||
|
local NET_DIR = '/sys/class/net'
|
||||||
|
|
||||||
local get_interfaces = function()
|
local get_interfaces = function()
|
||||||
local s = i_o.execute_cmd('realpath /sys/class/net/* | grep -v virtual')
|
local cmd = string.format('realpath %s/* | grep -v virtual', NET_DIR)
|
||||||
local interfaces = {}
|
local s = i_o.execute_cmd(cmd)
|
||||||
for iface in __string_gmatch(s, '/([^/\n]+)\n') do
|
local f = pure.partial(pure.gmatch_table, '/([^/\n]+)\n')
|
||||||
interfaces[#interfaces + 1] = iface
|
return pure.maybe({}, f, s)
|
||||||
end
|
|
||||||
return interfaces
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_net_interface_paths = function()
|
M.get_net_interface_paths = function()
|
||||||
local is = get_interfaces()
|
local is = get_interfaces()
|
||||||
return pure.map(
|
return pure.map(
|
||||||
function(s)
|
function(s)
|
||||||
local dir = string.format('/sys/class/net/%s/statistics/', s)
|
local dir = string.format('%s/%s/statistics/', NET_DIR, s)
|
||||||
return {rx = dir..'rx_bytes', tx = dir..'tx_bytes'}
|
return {rx = dir..'rx_bytes', tx = dir..'tx_bytes'}
|
||||||
end,
|
end,
|
||||||
is
|
is
|
||||||
|
|
Loading…
Reference in New Issue