fort/test/log_read.lua

49 lines
909 B
Lua
Raw Normal View History

2015-01-12 06:42:12 +00:00
-- WIPF Log Reader
local sys = require"sys"
2015-01-15 08:17:03 +00:00
local sock = require"sys.sock"
2015-01-12 06:42:12 +00:00
local wipf = require"wipflua"
2015-01-16 11:11:59 +00:00
function get_procpath(id)
local pid = sys.pid(id, true)
2015-01-16 11:16:05 +00:00
local path = (pid and pid:path()) or ""
pid:close()
return path
2015-01-16 11:11:59 +00:00
end
2015-01-14 15:06:56 +00:00
function print_logs(buf)
local size = buf:seek()
local ptr = buf:getptr()
local off = 0
while off < size do
local len, ip, pid, path = wipf.log_read(ptr, off)
2015-01-15 08:17:03 +00:00
local ip_str = sock.inet_ntop(ip)
2015-01-16 11:11:59 +00:00
if not path then
path = get_procpath(pid)
end
2015-01-15 08:17:03 +00:00
print(ip_str, pid, path)
2015-01-16 11:11:59 +00:00
off = off + len
2015-01-14 15:06:56 +00:00
end
buf:seek(0)
end
2015-01-12 12:49:02 +00:00
local device = assert(sys.handle():open(wipf.device_name(), "rw"))
2015-01-12 06:42:12 +00:00
2015-01-14 12:33:52 +00:00
local BUFSIZ = wipf.buffer_size()
2015-01-12 06:42:12 +00:00
local buf = assert(sys.mem.pointer(BUFSIZ))
2015-01-12 12:49:02 +00:00
assert(buf:write("test config"))
assert(device:ioctl(wipf.ioctl_setconf(), buf))
2015-01-12 06:42:12 +00:00
while true do
assert(device:ioctl(wipf.ioctl_getlog(), nil, buf))
2015-01-14 15:06:56 +00:00
print_logs(buf)
2015-01-12 06:42:12 +00:00
end