log rc errors to /tmp/event.log

closes #2787
This commit is contained in:
payonel 2018-03-20 19:30:00 -07:00
parent abe18ad535
commit aae7029dbe
2 changed files with 22 additions and 10 deletions

View File

@ -38,9 +38,11 @@ local function load(name, args)
if result then if result then
rc.loaded[name] = env rc.loaded[name] = env
return env return env
else
return nil, string.format("%s failed to start: %s", fileName, reason)
end end
end end
return nil, reason return nil, string.format("%s failed to load: %s", fileName, reason)
end end
function rc.unload(name) function rc.unload(name)
@ -116,24 +118,33 @@ local function allRunCommand(cmd, ...)
return results return results
end end
local stream = io.stderr
local write = stream.write
if select("#", ...) == 0 then if select("#", ...) == 0 then
-- if called during boot, pipe errors to onError handler
if _G.runlevel == "S" then
write = function(_, msg)
require("event").onError(msg)
end
end
local results, reason = allRunCommand("start") local results, reason = allRunCommand("start")
if not results then if not results then
local msg = "rc failed to start:"..tostring(reason) local msg = "rc failed to start:"..tostring(reason)
io.stderr:write(msg) write(stream, msg, "\n")
require("event").onError(msg)
return return
end end
for _, result in pairs(results) do for _, result in pairs(results) do
local ok, reason = table.unpack(result) local ok, reason = table.unpack(result)
if not ok then if not ok then
io.stderr:write(reason, "\n") write(stream, reason, "\n")
end end
end end
else else
local result, reason = runCommand(...) local result, reason = runCommand(...)
if not result then if not result then
io.stderr:write(reason, "\n") write(stream, reason, "\n")
return 1 return 1
end end
end end

View File

@ -8,10 +8,11 @@ local computer = computer
local unicode = unicode local unicode = unicode
-- Runlevel information. -- Runlevel information.
local runlevel, shutdown = "S", computer.shutdown _G.runlevel = "S"
computer.runlevel = function() return runlevel end local shutdown = computer.shutdown
computer.runlevel = function() return _G.runlevel end
computer.shutdown = function(reboot) computer.shutdown = function(reboot)
runlevel = reboot and 6 or 0 _G.runlevel = reboot and 6 or 0
if os.sleep then if os.sleep then
computer.pushSignal("shutdown") computer.pushSignal("shutdown")
os.sleep(0.1) -- Allow shutdown processing. os.sleep(0.1) -- Allow shutdown processing.