Compare commits
2 Commits
0aa574ea7a
...
1c647c76fe
Author | SHA1 | Date | |
---|---|---|---|
1c647c76fe | |||
5f56c74e6f |
24
lib/rpc.lua
24
lib/rpc.lua
@ -9,6 +9,8 @@ local function setacl(self, fname, host)
|
|||||||
self[fname] = self[fname] or {}
|
self[fname] = self[fname] or {}
|
||||||
self[fname][host] = true
|
self[fname][host] = true
|
||||||
end
|
end
|
||||||
|
-- function rpc.allow(fn, host) -- string string -- -- Enable the allow list for function *fname* and add *host* to it.
|
||||||
|
-- function rpc.deny(fn, host) -- string string -- -- Enable the deny list for function *fname* and add *host* to it.
|
||||||
rpc.allow = setmetatable({},{__call=setacl})
|
rpc.allow = setmetatable({},{__call=setacl})
|
||||||
rpc.deny = setmetatable({},{__call=setacl})
|
rpc.deny = setmetatable({},{__call=setacl})
|
||||||
|
|
||||||
@ -23,15 +25,15 @@ local function isPermitted(host,fn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function rpcexec(_, from, port, data)
|
local function rpcexec(_, from, port, data)
|
||||||
|
if port ~= rpc.port then return false end
|
||||||
os.spawn(function()
|
os.spawn(function()
|
||||||
if port == rpc.port then
|
local rpcrq = serial.unserialize(data) or {}
|
||||||
local rpcrq = serial.unserialize(data) or {}
|
if rpcf[rpcrq[1]] and isPermitted(from,rpcrq[1]) then
|
||||||
if rpcf[rpcrq[1]] and isPermitted(from,rpcrq[1]) then
|
os.setenv("RPC_CLIENT",from)
|
||||||
minitel.send(from,port,serial.serialize({rpcrq[2],pcall(rpcf[rpcrq[1]],table.unpack(rpcrq,3))}))
|
minitel.send(from,port,serial.serialize({rpcrq[2],pcall(rpcf[rpcrq[1]],table.unpack(rpcrq,3))}))
|
||||||
elseif type(rpcrq[2]) == "string" then
|
elseif type(rpcrq[2]) == "string" then
|
||||||
minitel.send(from,port,serial.serialize({rpcrq[2],false,"function unavailable"}))
|
minitel.send(from,port,serial.serialize({rpcrq[2],false,"function unavailable"}))
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end,"rpc worker for "..tostring(from))
|
end,"rpc worker for "..tostring(from))
|
||||||
end
|
end
|
||||||
function rpcf.list()
|
function rpcf.list()
|
||||||
@ -94,4 +96,10 @@ function rpc.register(name,fn) -- string function -- -- Registers a function to
|
|||||||
rpcf[name] = fn
|
rpcf[name] = fn
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function rpc.unregister(name) -- string -- -- Removes a function from the RPC function registry, clearing any ACL rules.
|
||||||
|
rpcf[name] = nil
|
||||||
|
rpc.allow[name] = nil
|
||||||
|
rpc.deny[name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
return rpc
|
return rpc
|
||||||
|
@ -41,7 +41,7 @@ end
|
|||||||
function os.taskInfo(pid) -- number -- table -- returns info on process *pid* as a table with name and parent values
|
function os.taskInfo(pid) -- number -- table -- returns info on process *pid* as a table with name and parent values
|
||||||
pid = pid or os.pid()
|
pid = pid or os.pid()
|
||||||
if not tTasks[pid] then return false end
|
if not tTasks[pid] then return false end
|
||||||
return {name=tTasks[pid].n,parent=tTasks[pid].P,cputime=tTasks[pid].t,iotime=tTasks[pid].T}
|
return {name=tTasks[pid].n,parent=tTasks[pid].P,cputime=tTasks[pid].t,iotime=tTasks[pid].T,timeout=tTasks[pid].E}
|
||||||
end
|
end
|
||||||
function os.sched() -- the actual scheduler function
|
function os.sched() -- the actual scheduler function
|
||||||
os.sched = nil
|
os.sched = nil
|
||||||
@ -60,7 +60,6 @@ function os.sched() -- the actual scheduler function
|
|||||||
tTasks[k] = nil
|
tTasks[k] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sTimeout = nTimeout
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function os.setenv(k,v) -- set's the current process' environment variable *k* to *v*, which is passed to children
|
function os.setenv(k,v) -- set's the current process' environment variable *k* to *v*, which is passed to children
|
||||||
@ -73,9 +72,6 @@ function os.getenv(k) -- gets a process' *k* environment variable
|
|||||||
return tTasks[cPid].e[k]
|
return tTasks[cPid].e[k]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function os.getTimeout()
|
|
||||||
return tTasks[cPid].E
|
|
||||||
end
|
|
||||||
function os.setTimeout(n,pid)
|
function os.setTimeout(n,pid)
|
||||||
assert(type(n) == "number" and n >= 0)
|
assert(type(n) == "number" and n >= 0)
|
||||||
tTasks[pid or cPid].E = n
|
tTasks[pid or cPid].E = n
|
||||||
|
Loading…
Reference in New Issue
Block a user