fixed keys added more OS syscalls and added colored logging
This commit is contained in:
@@ -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