mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-24 20:27:39 -05:00
Compare commits
4 Commits
be3d3c207f
...
d40ce731ef
Author | SHA1 | Date | |
---|---|---|---|
|
d40ce731ef | ||
|
417856ebd6 | ||
|
216e0a15c6 | ||
|
5938f75f4c |
17
lib/rc.lua
17
lib/rc.lua
@ -1,6 +1,7 @@
|
|||||||
local serial = require "serialization"
|
local serial = require "serialization"
|
||||||
|
|
||||||
local rc = {}
|
local rc = {}
|
||||||
|
rc.paths = "/boot/service\n/pkg/service"
|
||||||
rc.pids = {}
|
rc.pids = {}
|
||||||
local service = {}
|
local service = {}
|
||||||
local cfg = {}
|
local cfg = {}
|
||||||
@ -23,6 +24,21 @@ local function saveConfig()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function rc.load(name,force) -- string boolean -- table -- Attempts to load service *name*, and if *force* is true, replaces the current instance.
|
function rc.load(name,force) -- string boolean -- table -- Attempts to load service *name*, and if *force* is true, replaces the current instance.
|
||||||
|
if not package.loaded[name] or force then
|
||||||
|
for d in rc.paths:gmatch("[^\n]+") do
|
||||||
|
if fs.exists(d.."/"..name..".lua") then
|
||||||
|
service[name] = runfile(d.."/"..name..".lua")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if service[name] then
|
||||||
|
return service[name]
|
||||||
|
end
|
||||||
|
return false, "unable to load service "..name
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
function rc.load(name,force) -- string boolean -- table -- Attempts to load service *name*, and if *force* is true, replaces the current instance.
|
||||||
if force then
|
if force then
|
||||||
rc.stop(name)
|
rc.stop(name)
|
||||||
service[name] = nil
|
service[name] = nil
|
||||||
@ -39,6 +55,7 @@ function rc.load(name,force) -- string boolean -- table -- Attempts to load serv
|
|||||||
f:close()
|
f:close()
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
function rc.stop(name,...) -- string -- boolean string -- Stops service *name*, supplying *...* to the stop function. Returns false and a reason if this fails.
|
function rc.stop(name,...) -- string -- boolean string -- Stops service *name*, supplying *...* to the stop function. Returns false and a reason if this fails.
|
||||||
if not service[name] then return false, "service not found" end
|
if not service[name] then return false, "service not found" end
|
||||||
|
@ -7,10 +7,7 @@ end
|
|||||||
function runfile(p,...) -- string -- -- runs file *p* with arbitrary arguments in the current thread
|
function runfile(p,...) -- string -- -- runs file *p* with arbitrary arguments in the current thread
|
||||||
return loadfile(p)(...)
|
return loadfile(p)(...)
|
||||||
end
|
end
|
||||||
function os.spawnfile(p,n,...) -- string string -- number -- spawns a new process from file *p* with name *n*, with arguments following *n*.
|
|
||||||
local tA = {...}
|
|
||||||
return os.spawn(function() local res={pcall(loadfile(p), table.unpack(tA))} computer.pushSignal("process_finished", os.pid(), table.unpack(res)) dprint(table.concat(res)) end,n or p)
|
|
||||||
end
|
|
||||||
_G.package = {}
|
_G.package = {}
|
||||||
package.path="./?;./?.lua;/boot/lib/?.lua;/pkg/lib/?.lua;/boot/lib/?/init.lua;/pkg/lib/?/init.lua"
|
package.path="./?;./?.lua;/boot/lib/?.lua;/pkg/lib/?.lua;/boot/lib/?/init.lua;/pkg/lib/?/init.lua"
|
||||||
package.loaded = {computer=computer,component=component,fs=fs,buffer=buffer}
|
package.loaded = {computer=computer,component=component,fs=fs,buffer=buffer}
|
||||||
|
@ -2,7 +2,13 @@ do
|
|||||||
local tTasks,nPid,nTimeout,cPid = {},1,0.25,0 -- table of tasks, next process ID, event timeout, current PID
|
local tTasks,nPid,nTimeout,cPid = {},1,0.25,0 -- table of tasks, next process ID, event timeout, current PID
|
||||||
function os.spawn(f,n) -- function string -- number -- creates a process from function *f* with name *n*
|
function os.spawn(f,n) -- function string -- number -- creates a process from function *f* with name *n*
|
||||||
tTasks[nPid] = {
|
tTasks[nPid] = {
|
||||||
c=coroutine.create(f), -- actual coroutine
|
c=coroutine.create(function()
|
||||||
|
local rt = {pcall(f)}
|
||||||
|
if not rt[1] then
|
||||||
|
syslog(rt[2])
|
||||||
|
end
|
||||||
|
computer.pushSignal("process_finished",os.pid(),table.unpack(rt))
|
||||||
|
end), -- actual coroutine
|
||||||
n=n, -- process name
|
n=n, -- process name
|
||||||
p=nPid, -- process PID
|
p=nPid, -- process PID
|
||||||
P=cPid, -- parent PID
|
P=cPid, -- parent PID
|
||||||
|
@ -37,7 +37,7 @@ local function spawnShell(fin,fout)
|
|||||||
io.input(fin)
|
io.input(fin)
|
||||||
io.output(fout):setvbuf("no")
|
io.output(fout):setvbuf("no")
|
||||||
print(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
|
print(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM")
|
||||||
return os.spawn(shell.interactive, "shell: "..tostring(fin))
|
return os.spawn(function() local w,r = pcall(shell.interactive) if not w then syslog(r) end end, "shell: "..tostring(fin))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function allocate()
|
local function allocate()
|
||||||
@ -77,3 +77,4 @@ function stop()
|
|||||||
os.kill(basepid)
|
os.kill(basepid)
|
||||||
basepid = nil
|
basepid = nil
|
||||||
end
|
end
|
||||||
|
return {start=start,stop=stop}
|
||||||
|
@ -271,3 +271,4 @@ function del_route(to)
|
|||||||
cfg.sroutes[to] = nil
|
cfg.sroutes[to] = nil
|
||||||
saveconfig()
|
saveconfig()
|
||||||
end
|
end
|
||||||
|
return {start=start,stop=stop,set=set,set_route=set_route,del_route=del_route}
|
||||||
|
Loading…
Reference in New Issue
Block a user