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
rc.loaded[name] = env
return env
else
return nil, string.format("%s failed to start: %s", fileName, reason)
end
end
return nil, reason
return nil, string.format("%s failed to load: %s", fileName, reason)
end
function rc.unload(name)
@ -116,24 +118,33 @@ local function allRunCommand(cmd, ...)
return results
end
if select("#", ...) == 0 then
local results,reason = allRunCommand("start")
local stream = io.stderr
local write = stream.write
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")
if not results then
local msg = "rc failed to start:"..tostring(reason)
io.stderr:write(msg)
require("event").onError(msg)
write(stream, msg, "\n")
return
end
for _, result in pairs(results) do
local ok, reason = table.unpack(result)
if not ok then
io.stderr:write(reason, "\n")
write(stream, reason, "\n")
end
end
else
local result, reason = runCommand(...)
if not result then
io.stderr:write(reason, "\n")
write(stream, reason, "\n")
return 1
end
end

View File

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