From d40ce731ef0187adb1be2f6098f3c651a32aba6e Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 29 Jun 2020 15:31:32 +1000 Subject: [PATCH] made rc enforce the new service semantics --- lib/rc.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/rc.lua b/lib/rc.lua index e4f1f52..b5ea311 100644 --- a/lib/rc.lua +++ b/lib/rc.lua @@ -1,6 +1,7 @@ local serial = require "serialization" local rc = {} +rc.paths = "/boot/service\n/pkg/service" rc.pids = {} local service = {} local cfg = {} @@ -22,6 +23,21 @@ local function saveConfig() return true end +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 rc.stop(name) @@ -39,6 +55,7 @@ function rc.load(name,force) -- string boolean -- table -- Attempts to load serv f:close() return res end +]] 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