fixed keys added more OS syscalls and added colored logging
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
local userhost = syscall.OS_getUser().."@"..syscall.OS_getHostname()
|
||||
local userhost = (syscall.OS_getUser() or "Unknown").."@"..(syscall.OS_getHostname() or "Unknown")
|
||||
print(".. *. .. | "..userhost)
|
||||
print(" *= +@* +* | "..string.rep("-",#userhost))
|
||||
print(" .@#. -@@@= :#@. | OS: "..syscall.OS_version())
|
||||
print(" =@@+ *@@@# +@@= | Host: "..syscall.OS_getHost())
|
||||
print(" %@@%: *@@@# -%@@% | Uptime: "..syscall.OS_getUptime())
|
||||
print(" :@@@@+ *@@@# .*@@@@: | Tasks: "..tostring(#syscall.HPV_list()))
|
||||
print(" :*@@@%- *@@@# -@@@@*: | Packages: "..tostring())
|
||||
print(" =%@@#. *@@@# .#@@%= | Shell: "..syscall.HPV_getEnviron("SHELL"))
|
||||
print(" .@#. -@@@= :#@. | OS: "..(syscall.OS_version() or "Unknown"))
|
||||
print(" =@@+ *@@@# +@@= | Host: "..(syscall.OS_getHost() or "Unknown"))
|
||||
print(" %@@%: *@@@# -%@@% | Uptime: "..(syscall.OS_getUptime() or "Unknown"))
|
||||
print(" :@@@@+ *@@@# .*@@@@: | Tasks: "..tostring((#syscall.HPV_list() or "Unknown")))
|
||||
print(" :*@@@%- *@@@# -@@@@*: | Packages: ".."Unknown")
|
||||
print(" =%@@#. *@@@# .#@@%= | Shell: "..(syscall.HPV_getEnviron("SHELL") or "Unknown"))
|
||||
print(" :=. :*@@= *@@@# =@@+: .=: | ")
|
||||
print(" %@#=..*# +@@@# #*..=#@# | ")
|
||||
print(" .@@@@+=# .%@%: #=+@@@@. | ")
|
||||
|
||||
@@ -29,13 +29,18 @@ for i,v in ipairs(files) do
|
||||
else
|
||||
syscall.HPV_spawn(function()
|
||||
syscall.IO_bind("eventQueue:"..tostring(i))
|
||||
eventQueues[#eventQueues+1]="eventQueue:"..tostring(i)
|
||||
local spot = #eventQueues+1
|
||||
eventQueues[spot]="eventQueue:"..tostring(i)
|
||||
local status, err = pcall(startupFunc)
|
||||
if not status then
|
||||
kernel.log("Error executing startup script '" .. filepath .. "': " .. err, "ERROR")
|
||||
else
|
||||
kernel.log("Successfully executed startup script: " .. filepath, "INFO")
|
||||
end
|
||||
local event={true}
|
||||
while event[1] do
|
||||
syscall.IO_pullEvent()
|
||||
end
|
||||
end, "startup:" .. v)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,11 @@ local function write(text)
|
||||
if c == "\n" then
|
||||
y = y + 1
|
||||
x = 1
|
||||
if y-1 >= h then
|
||||
term.scroll(1)
|
||||
y = h
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
elseif c == "\t" then
|
||||
local tabSize = 4
|
||||
local spaces = tabSize - ((x - 1) % tabSize)
|
||||
@@ -38,7 +43,7 @@ local function write(text)
|
||||
y = y + 1
|
||||
end
|
||||
|
||||
if y-1 > h then
|
||||
if y-1 >= h then
|
||||
term.scroll(1)
|
||||
y = h
|
||||
term.setCursorPos(x, y)
|
||||
@@ -66,7 +71,6 @@ local ok, err = xpcall(function()
|
||||
local lua = {
|
||||
coroutine = true,
|
||||
debug = true,
|
||||
_HOST = true,
|
||||
_VERSION = true,
|
||||
assert = true,
|
||||
collectgarbage = true,
|
||||
@@ -160,7 +164,7 @@ local ok, err = xpcall(function()
|
||||
|
||||
local computer = {
|
||||
time = function() return apis.os.epoch("utc") end,
|
||||
clock = function() return apis.os.clock()/1000 end,
|
||||
clock = function() return apis.os.clock()*1000 end,
|
||||
shutdown = apis.os.shutdown,
|
||||
reboot = apis.os.reboot,
|
||||
getMachineEvent = function()
|
||||
|
||||
@@ -63,13 +63,13 @@ tKeys[keys.pageUp] = '\x1b[5~'
|
||||
tKeys[keys.pageDown] = '\x1b[6~'
|
||||
tKeys[keys.home] = '\x1b[1~'
|
||||
tKeys[keys["end"]] = '\x1b[4~'
|
||||
tKeys[keys.capsLock] = '\x1b[capsLock'
|
||||
tKeys[keys.scrollLock] = '\x1b[scrollLock'
|
||||
tKeys[keys.numLock] = '\x1b[numLock'
|
||||
if keys.printScreen then
|
||||
tKeys[keys.printScreen] = '\x1b[printScreen'
|
||||
end
|
||||
tKeys[keys.pause] = '\x1b[pause'
|
||||
--tKeys[keys.capsLock] = '\x1b[capsLock'
|
||||
--tKeys[keys.scrollLock] = '\x1b[scrollLock'
|
||||
--tKeys[keys.numLock] = '\x1b[numLock'
|
||||
--if keys.printScreen then
|
||||
-- tKeys[keys.printScreen] = '\x1b[printScreen'
|
||||
--end
|
||||
--tKeys[keys.pause] = '\x1b[pause'
|
||||
tKeys[keys.f1] = '\x1b[11~'
|
||||
tKeys[keys.f2] = '\x1b[12~'
|
||||
tKeys[keys.f3] = '\x1b[13~'
|
||||
|
||||
@@ -8,9 +8,11 @@ local computer = args[6]
|
||||
local ifs = args[7]
|
||||
local kernel = {}
|
||||
kernel.LOG_Text=""
|
||||
kernel.version="HyperionOS V1.0.0"
|
||||
kernel.process = "Kernel"
|
||||
kernel.user = "root"
|
||||
kernel.group = "root"
|
||||
kernel.hostname = "hyperion"
|
||||
kernel.groups = {0}
|
||||
kernel.uid = 0
|
||||
kernel.gid = 0
|
||||
@@ -24,13 +26,16 @@ kernel.sleep=sleep
|
||||
_G.sleep=nil
|
||||
local windowsExp = false
|
||||
|
||||
function kernel.log(msg, level)
|
||||
function kernel.log(msg, level, c)
|
||||
c=c or 12
|
||||
kernel.LOG_Text = kernel.LOG_Text..tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg.."\n"
|
||||
if kernel.status == "start" then
|
||||
screen:setTextColor(c)
|
||||
screen:print(tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg)
|
||||
elseif kernel.status == "init" then
|
||||
kernel.standbyTask=kernel.currentTask
|
||||
kernel.currentTask=kernel.kernelTask
|
||||
kernel.tty.setTextColor(c)
|
||||
kernel.tty.print(tostring(computer:time()).." "..kernel.user.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg)
|
||||
kernel.currentTask=kernel.standbyTask
|
||||
end
|
||||
@@ -109,7 +114,7 @@ local split = function(str, delim, maxResultCountOrNil)
|
||||
end
|
||||
|
||||
if not ifs.isFile("/boot/boot.cfg") then
|
||||
kernel.log("boot.cfg missing or corrupted!, Attempting to write recovery boot.cfg", "ERROR")
|
||||
kernel.log("boot.cfg missing or corrupted!, Attempting to write recovery boot.cfg", "ERROR", 2)
|
||||
ifs.writeAllText("/boot/boot.cfg",ifs.readAllText("/boot/safeboot.cfg"))
|
||||
end
|
||||
|
||||
@@ -230,13 +235,20 @@ end
|
||||
|
||||
kernel.syscalls["OS_time"]=function() return kernel.computer:time() end
|
||||
kernel.syscalls["OS_log"]=kernel.log
|
||||
kernel.syscalls["OS_getUptime"]=function() return kernel.computer:clock() end
|
||||
kernel.syscalls["OS_getUser"]=function() return kernel.user end
|
||||
kernel.syscalls["OS_getHostname"]=function() return kernel.host end
|
||||
kernel.syscalls["OS_getHost"]=function() return kernel.apis._HOST end
|
||||
kernel.syscalls["OS_version"]=function() return kernel.version end
|
||||
kernel.syscalls["OS_setHostname"]=function(name) if kernel.uid~=0 then error("Permission denied") end kernel.hostname=name end
|
||||
kernel.syscalls["OS_setUser"]=function(uid) if kernel.uid~=0 then error("Permission denied") end kernel.currentTask.uid=uid end
|
||||
|
||||
kernel.log("Running modules")
|
||||
for _,p in ipairs(modules) do
|
||||
for _,v in ipairs(p) do
|
||||
local code=ifs.readAllText(v)
|
||||
if not code then
|
||||
kernel.log("ModuReadErr: "..v, "WARN")
|
||||
kernel.log("ModuReadErr: "..v, "WARN", 8)
|
||||
goto skip
|
||||
end
|
||||
local func,err=load(code,"@"..v)
|
||||
|
||||
@@ -5,7 +5,7 @@ for i,v in ipairs(string.split(kernel.fstab,"\n")) do
|
||||
local id=""
|
||||
for i=3,#v do
|
||||
if v:sub(i,i)==";" then
|
||||
if i==3 then kernel.log("Invalid fstab line... Skipping.","WARN") goto endline end
|
||||
if i==3 then kernel.log("Invalid fstab line... Skipping.","WARN", 8) goto endline end
|
||||
id=v:sub(3,i-1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ function sys.spawn(func, name, envars, args, tgid)
|
||||
local ok, err = xpcall(func, debug.traceback, table.unpack(args or {}))
|
||||
if not ok then
|
||||
if kernel.config.logTaskExit then
|
||||
kernel.log("Task "..tostring(id).." exited with err: "..tostring(err), "ERROR")
|
||||
kernel.log("Task "..tostring(id).." exited with err: "..tostring(err), "ERROR", 2)
|
||||
end
|
||||
tasks[tostring(id)].status="Z"
|
||||
tasks[tostring(id)].exit=err
|
||||
@@ -123,7 +123,7 @@ function sys.kill(pid)
|
||||
end
|
||||
if not tasks[tostring(pid)] then
|
||||
return false, "Task does not exist"
|
||||
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) then
|
||||
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) and kernel.uid~=0 then
|
||||
return false, "You do not own this task"
|
||||
elseif tasks[tostring(pid)].status=="Z" then
|
||||
return false, "Task is already dead"
|
||||
@@ -140,7 +140,7 @@ function sys.stop(pid)
|
||||
end
|
||||
if not tasks[tostring(pid)] then
|
||||
return false, "Task does not exist"
|
||||
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) then
|
||||
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) and kernel.uid~=0 then
|
||||
return false, "You do not own this task"
|
||||
elseif tasks[tostring(pid)].status~="R" then
|
||||
return false, "Cannot stop non running task"
|
||||
@@ -157,7 +157,7 @@ function sys.continue(pid)
|
||||
end
|
||||
if not tasks[tostring(pid)] then
|
||||
return false, "Task does not exist"
|
||||
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) then
|
||||
elseif not isEqualToAny(tasks[tostring(pid)].pid,table.unpack(children)) and kernel.uid~=0 then
|
||||
return false, "You do not own this task"
|
||||
elseif tasks[tostring(pid)].status~="T" then
|
||||
return false, "Task is not stopped"
|
||||
@@ -271,6 +271,7 @@ function kernel.main()
|
||||
kernel.vfs.cwd = task.cwd
|
||||
kernel.user = task.user
|
||||
kernel.uid = task.uid
|
||||
kernel.process = task.name
|
||||
N = N + 1
|
||||
|
||||
-- assign adaptive time slice
|
||||
@@ -298,7 +299,7 @@ function kernel.main()
|
||||
|
||||
-- handle task results
|
||||
if ret[1] == "error" then
|
||||
kernel.log("processHandlerException: "..ret[2])
|
||||
kernel.log("processHandlerException: "..ret[2], "ERROR", 2)
|
||||
task.status = "Z"
|
||||
task.exit = "processHandlerException: "..ret[2]
|
||||
elseif ret[1] == "timeout" then
|
||||
@@ -309,22 +310,22 @@ function kernel.main()
|
||||
if ret[2]=="syscall" then
|
||||
if kernel.syscalls[ret[3]] then
|
||||
if kernel.config.debugSyscalls then
|
||||
kernel.log("Task "..task.pid.." invoking syscall: "..ret[3], "DBUG")
|
||||
kernel.log("Task "..task.pid.." invoking syscall: "..ret[3], "DBUG", 5)
|
||||
for i=4,#ret do
|
||||
kernel.log(" inval["..tostring(i-3).."] = "..tostring(ret[i]), "DBUG")
|
||||
kernel.log(" inval["..tostring(i-3).."] = "..tostring(ret[i]), "DBUG", 5)
|
||||
end
|
||||
end
|
||||
local sysret = {xpcall(kernel.syscalls[ret[3]], debug.traceback, table.unpack(ret, 4))}
|
||||
if kernel.config.debugSyscalls then
|
||||
if not sysret[1] then
|
||||
kernel.log("Task "..task.pid.." syscall "..ret[3].." failed: "..tostring(sysret[2]))
|
||||
kernel.log("Task "..task.pid.." syscall "..ret[3].." failed: "..tostring(sysret[2]), "ERROR", 2)
|
||||
else
|
||||
kernel.log("Task "..task.pid.." syscall "..ret[3].." completed returning "..tostring(#sysret-1).." values", "DBUG")
|
||||
kernel.log("Task "..task.pid.." syscall "..ret[3].." completed returning "..tostring(#sysret-1).." values", "DBUG", 5)
|
||||
for i=2,#sysret do
|
||||
if type(sysret[i])=="table" then
|
||||
kernel.log(" retval["..tostring(i-1).."] = "..table.serialize(sysret[i]), "DBUG")
|
||||
kernel.log(" retval["..tostring(i-1).."] = "..table.serialize(sysret[i]), "DBUG", 5)
|
||||
else
|
||||
kernel.log(" retval["..tostring(i-1).."] = "..tostring(sysret[i]), "DBUG")
|
||||
kernel.log(" retval["..tostring(i-1).."] = "..tostring(sysret[i]), "DBUG", 5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,6 +27,8 @@ kernel.tasks["1"] = {
|
||||
user="root",
|
||||
uid=0,
|
||||
fd={},
|
||||
envars={},
|
||||
args={},
|
||||
exit="",
|
||||
sleep=0,
|
||||
ivs=0,
|
||||
|
||||
Reference in New Issue
Block a user