stuff.mp4
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
local args={...}
|
||||
local os=require("os")
|
||||
local io=require("io")
|
||||
local text=""
|
||||
local blockKeyEvents=false
|
||||
io.link(io.focas)
|
||||
|
||||
os.hookSignal("keyTyped", function(_, screen, key)
|
||||
if blockKeyEvents then return end
|
||||
if key == "\n" then
|
||||
blockKeyEvents=true
|
||||
elseif key == "\b" then
|
||||
text=text:sub(1,#text-1)
|
||||
io.stdout.printInline("\b")
|
||||
else
|
||||
text=text..key
|
||||
io.stdout.printInline(key)
|
||||
end
|
||||
end)
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+33
@@ -192,5 +192,38 @@ local function serialize(table)
|
||||
return output
|
||||
end
|
||||
|
||||
local oldtype=type
|
||||
local oldgetmetatable=getmetatable
|
||||
function type(object)
|
||||
if oldtype(object)~="table" then
|
||||
return oldtype(object)
|
||||
else
|
||||
if oldtype(oldgetmetatable(object))=="table" then
|
||||
local metatable = oldgetmetatable(object)
|
||||
if metatable.__type then return metatable.__type end
|
||||
else
|
||||
return "table"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function getmetatable(object)
|
||||
if oldtype(object)~="table" then return end
|
||||
if oldtype(oldgetmetatable(object))=="table" then
|
||||
if oldgetmetatable(object).__isuserdata then
|
||||
if oldtype(oldgetmetatable(object).__usermeta)=="function" then
|
||||
return oldgetmetatable(object).__usermeta()
|
||||
else
|
||||
return oldgetmetatable(object).__usermeta
|
||||
end
|
||||
else
|
||||
return oldgetmetatable(object)
|
||||
end
|
||||
else
|
||||
return oldgetmetatable(object)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
table.serialize=serialize
|
||||
kernel.log("Loaded stdlib")
|
||||
Executable → Regular
Executable → Regular
+33
-3
@@ -8,6 +8,7 @@ local fs = {}
|
||||
|
||||
local disks = {} -- address → disk object
|
||||
local mounts = {["/"] = "$"} -- mountpoint → disk address (root = boot disk)
|
||||
local cwd = "/"
|
||||
|
||||
local SYMLINK_PREFIX = "#!@SYMLINK["
|
||||
local SYMLINK_SUFFIX = "]"
|
||||
@@ -27,10 +28,11 @@ end
|
||||
local function normalizePath(path)
|
||||
if not path or path == "" then return "/" end
|
||||
|
||||
-- ensure absolute
|
||||
-- cwd
|
||||
if path:sub(1,1) ~= "/" then
|
||||
path = "/" .. path
|
||||
path=cwd..path
|
||||
end
|
||||
|
||||
|
||||
local parts = splitPath(path)
|
||||
local out = {}
|
||||
@@ -300,7 +302,35 @@ function fs.getSize(path, ...)
|
||||
return disk:getSize(p, ...)
|
||||
end
|
||||
|
||||
-- =====================================================================
|
||||
-- WD STUFF
|
||||
-- =====================================================================
|
||||
|
||||
function fs.setCwd(path)
|
||||
if not path or path == "" then return "/" end
|
||||
|
||||
-- ensure absolute
|
||||
if path:sub(1,1) ~= "/" then
|
||||
path = "/" .. path
|
||||
end
|
||||
|
||||
local parts = splitPath(path)
|
||||
local out = {}
|
||||
|
||||
for _,part in ipairs(parts) do
|
||||
if part == ".." then
|
||||
if #out > 0 then table.remove(out) end
|
||||
elseif part ~= "." and part ~= "" then
|
||||
out[#out+1] = part
|
||||
end
|
||||
end
|
||||
|
||||
cwd="/" .. table.concat(out, "/")
|
||||
end
|
||||
|
||||
function fs.getCwd(path)
|
||||
return cwd
|
||||
end
|
||||
|
||||
-- =====================================================================
|
||||
-- INIT
|
||||
@@ -317,5 +347,5 @@ if not ok then kernel.panic(err) end
|
||||
kernel.disks=disks
|
||||
kernel.mounts=mounts
|
||||
kernel.fs = fs
|
||||
kernel.cache.preload.fs = table.proxy(kernel.fs)
|
||||
kernel.cache.preload.fs = fs
|
||||
kernel.cache.preload.filesystem = kernel.cache.preload.fs
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+2
-2
@@ -1,10 +1,10 @@
|
||||
local args = {...}
|
||||
local kernel = args[1]
|
||||
kernel.drivers.processes[#kernel.drivers.processes+1]=function()
|
||||
kernel.drivers.processes["keventd"]=function()
|
||||
while true do
|
||||
local event={kernel.computer:getMachineEvent()}
|
||||
while event[1]~=nil do
|
||||
kernel.hpv.sendSig("all", table.unpack(event))
|
||||
kernel.hpv.sendSignal("all", table.unpack(event))
|
||||
event={kernel.computer:getMachineEvent()}
|
||||
end
|
||||
coroutine.yield()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
local args={...}
|
||||
local kernel=args[1]
|
||||
local io={}
|
||||
local iolib={}
|
||||
|
||||
io.stdout={}
|
||||
io.stdin={}
|
||||
io.stderr={}
|
||||
|
||||
iolib.stdout=io.stdout
|
||||
iolib.stdin =io.stdin
|
||||
iolib.stderr=io.stderr
|
||||
|
||||
function io.register(ttyObj)
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+52
-11
@@ -8,7 +8,7 @@ local gid=2
|
||||
local hookuuid=0
|
||||
local sys={}
|
||||
|
||||
function sys.hookSig(sig, func)
|
||||
function sys.hookSignal(sig, func)
|
||||
if not currentTask.signal[sig] then
|
||||
currentTask.signal[sig]={}
|
||||
end
|
||||
@@ -22,7 +22,7 @@ function sys.hookSig(sig, func)
|
||||
}
|
||||
end
|
||||
|
||||
function sys.clearSigHooks(typ)
|
||||
function sys.clearSignalHooks(typ)
|
||||
if not typ or typ == "all" then
|
||||
signals[tostring(currentTask.pid)]={}
|
||||
currentTask.signal=signals[tostring(currentTask.pid)]
|
||||
@@ -33,9 +33,9 @@ function sys.clearSigHooks(typ)
|
||||
end
|
||||
end
|
||||
|
||||
function sys.sendSig(pid, signal, ...)
|
||||
function sys.sendSignal(pid, signal, ...)
|
||||
if pid=="all" then
|
||||
for i,v in pairs(tasks) do+
|
||||
for i,v in pairs(tasks) do
|
||||
v.sigQ[#v.sigQ+1]={signal, ...}
|
||||
end
|
||||
return
|
||||
@@ -57,7 +57,7 @@ function sys.flushSigs()
|
||||
coroutine.resumeWithTimeout(coroutine.create(function()
|
||||
local ok,err = xpcall(v,debug.traceback,table.unpack(sig))
|
||||
if not ok and sig[1]~="callbackErr" then
|
||||
sys.sendSig(currentTask.pid, "callbackErr", sig[1], k, err)
|
||||
sys.sendSignal(currentTask.pid, "callbackErr", sig[1], k, err)
|
||||
end
|
||||
end),10)
|
||||
end
|
||||
@@ -66,7 +66,7 @@ function sys.flushSigs()
|
||||
coroutine.resumeWithTimeout(coroutine.create(function()
|
||||
local ok,err = xpcall(v,debug.traceback,table.unpack(sig))
|
||||
if not ok and sig[1]~="callbackErr" then
|
||||
sys.sendSig(currentTask.pid, "callbackErr", sig[1], k, err)
|
||||
sys.sendSignal(currentTask.pid, "callbackErr", sig[1], k, err)
|
||||
end
|
||||
end),10)
|
||||
end
|
||||
@@ -74,7 +74,7 @@ function sys.flushSigs()
|
||||
end
|
||||
end
|
||||
|
||||
function sys.spawn(func, name, evars, args, stdin, stdout, stderr)
|
||||
function sys.spawn(func, name, evars, args)
|
||||
local id=tid
|
||||
tid=tid+1
|
||||
name=name or tostring(id)
|
||||
@@ -84,14 +84,15 @@ function sys.spawn(func, name, evars, args, stdin, stdout, stderr)
|
||||
coro=coroutine.create(function()
|
||||
local ret = {xpcall(func, debug.traceback, table.unpack(args))}
|
||||
if not ret[1] then
|
||||
sys.sendSig(currentTask.ppid, "ChildTaskError", id, err)
|
||||
sys.sendSignal(currentTask.ppid, "ChildTaskError", id, err)
|
||||
else
|
||||
sys.sendSig(currentTask.ppid, "ChildTaskExit", id, table.unpack(ret, 2))
|
||||
sys.sendSignal(currentTask.ppid, "ChildTaskExit", id, table.unpack(ret, 2))
|
||||
end
|
||||
currentTask.status="Z"
|
||||
end),
|
||||
name=name,
|
||||
pid=id,
|
||||
cwd=currentTask.cwd,
|
||||
ppid=currentTask.pid,
|
||||
tgid=currentTask.tgid,
|
||||
user=kernel.user,
|
||||
@@ -108,10 +109,46 @@ function sys.spawn(func, name, evars, args, stdin, stdout, stderr)
|
||||
sibling=currentTask.children,
|
||||
sigQ={}
|
||||
}
|
||||
return id
|
||||
end
|
||||
|
||||
function sys.spawnFromFile(path, name, envars, args)
|
||||
sys.spawn(kernel.fs.load(path), name, envars, args)
|
||||
end
|
||||
|
||||
function sys.spawnAndWait(func, name, envars, args)
|
||||
local id=sys.spawn(func, name, envars, args)
|
||||
local exit = false
|
||||
local errored = false
|
||||
local rets = {}
|
||||
|
||||
local hext=sys.hookSignal("ChildTaskExit",function(pid, ...)
|
||||
if pid==id then
|
||||
rets={...}
|
||||
exit=true
|
||||
end
|
||||
end)
|
||||
|
||||
local herr=sys.hookSignal("ChildTaskError",function(pid, ...)
|
||||
if pid==id then
|
||||
rets={...}
|
||||
exit=true
|
||||
errored=true
|
||||
end
|
||||
end)
|
||||
|
||||
while not exit do
|
||||
coroutine.yield()
|
||||
end
|
||||
return not errored, table.unpack(rets)
|
||||
end
|
||||
|
||||
function sys.spawnFromFileAndWait(path, name, envars, args)
|
||||
return sys.spawnAndWait(kernel.fs.load(path), name, envars, args)
|
||||
end
|
||||
|
||||
function sys.exit(...)
|
||||
sys.sendSig(currentTask.ppid, "ChildTaskExit", currentTask.pid, ...)
|
||||
sys.sendSignal(currentTask.ppid, "ChildTaskExit", currentTask.pid, ...)
|
||||
currentTask.status="Z"
|
||||
coroutine.yield()
|
||||
end
|
||||
@@ -157,6 +194,7 @@ tasks["1"]={
|
||||
end),
|
||||
name="SysInit",
|
||||
pid=1,
|
||||
cwd="",
|
||||
ppid=0,
|
||||
tgid=1,
|
||||
user="root",
|
||||
@@ -176,7 +214,7 @@ tasks["1"]={
|
||||
tasks["1"].sibling={tasks["1"]}
|
||||
|
||||
kernel.log("Created pid 1")
|
||||
kernel.cache.preload.sys=table.proxy(sys)
|
||||
kernel.cache.preload.sys=sys
|
||||
kernel.cache.preload.system=kernel.cache.preload.sys
|
||||
kernel.cache.preload.os=kernel.cache.preload.sys
|
||||
kernel.hpv=sys
|
||||
@@ -189,10 +227,12 @@ kernel.status="running"
|
||||
while kernel.status~="Panic" do
|
||||
for k,v in pairs(tasks) do
|
||||
currentTask=v
|
||||
kernel.computer:print(currentTask.name)
|
||||
kernel.currentTask=v
|
||||
kernel.process=currentTask.name
|
||||
kernel.user=currentTask.user
|
||||
kernel.uid=currentTask.uid
|
||||
kernel.fs.setCwd(currentTask.cwd)
|
||||
sys.flushSigs()
|
||||
local status = coroutine.resumeWithTimeout(currentTask.coro, 50)
|
||||
if status then
|
||||
@@ -200,6 +240,7 @@ while kernel.status~="Panic" do
|
||||
else
|
||||
currentTask.ivy=currentTask.ivy+1
|
||||
end
|
||||
currentTask.cwd=kernel.fs.getCwd()
|
||||
end
|
||||
collectZombieProc()
|
||||
end
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
local userdata={}
|
||||
userdata.policy={}
|
||||
userdata.policy.readOnly=1
|
||||
userdata.policy.readWrite=2
|
||||
userdata.policy.WriteOnly=3
|
||||
userdata.policy.hidden=4
|
||||
userdata.policy.custom=5
|
||||
|
||||
function userdata.create()
|
||||
return setmetatable()
|
||||
end
|
||||
Executable → Regular
+3
@@ -1,3 +1,6 @@
|
||||
local args={...}
|
||||
local kernel=args[1]
|
||||
for i,v in pairs(kernel.drivers.processes) do
|
||||
os.spawn(v, i, {}, {})
|
||||
end
|
||||
kernel.fs.load("/bin/bash")()
|
||||
Reference in New Issue
Block a user