Added runlevel information, mainly to allow rc scripts to tell if they're run during startup (where primaries may not be set, yet, so they'll have to wait for the init event) or not.

This commit is contained in:
Florian Nücke 2014-10-25 12:36:25 +02:00
parent c31b74f811
commit aa55f1fc1d
3 changed files with 15 additions and 3 deletions

View File

@ -9,5 +9,6 @@ function start(msg)
print(msg)
end
print(count)
print("runlevel: " .. require("computer").runlevel())
count = count + 1
end

View File

@ -5,6 +5,18 @@ do
local computer = computer
local unicode = unicode
-- Runlevel information.
local runlevel, shutdown = "S", computer.shutdown
computer.runlevel = function() return runlevel end
computer.shutdown = function(reboot)
runlevel = reboot and 6 or 0
if os.sleep then
computer.pushSignal("shutdown")
os.sleep(0.1) -- Allow shutdown processing.
end
shutdown(reboot)
end
-- Low level dofile implementation to read filesystem libraries.
local rom = {}
function rom.invoke(method, ...)
@ -151,10 +163,9 @@ do
computer.pushSignal("init") -- so libs know components are initialized.
status("Initializing system...")
os.sleep(0.1)
require("term").clear()
os.sleep(0.1) -- Allow init processing.
runlevel = 1
end
local function motd()

View File

@ -1241,7 +1241,7 @@ local libcomputer = {
end,
shutdown = function(reboot)
coroutine.yield(reboot ~= nil and reboot ~= false)
coroutine.yield(not not reboot)
end,
pushSignal = function(...)
return spcall(computer.pushSignal, ...)