From 6ad6880a6dcda933f08440e29a14b02ab1d14853 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sat, 9 Nov 2019 14:23:18 +1100 Subject: [PATCH] rewrote init.lua to be a real init daemon --- build.sh | 4 +++- default-init.txt | 4 +--- exec/init.lua | 34 ++++++++++++++++++++++------------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/build.sh b/build.sh index 0560e70..7acd9a5 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,11 @@ #!/bin/sh rm -r target/* -mkdir target +mkdir target &>/dev/null +mkdir target/cfg lua luapreproc.lua module/init.lua target/init.lua echo _OSVERSION=\"PsychOS 2.0a1-$(git rev-parse --short HEAD)\" > target/version.lua cat target/version.lua target/init.lua > target/tinit.lua mv target/tinit.lua target/init.lua cp -r exec/ service/ lib/ target/ +cp default-init.txt target/cfg/ lua finddesc.lua $(find module/ -type f) $(find lib/ -type f) > apidoc.md diff --git a/default-init.txt b/default-init.txt index 854d252..f42499a 100644 --- a/default-init.txt +++ b/default-init.txt @@ -1,3 +1 @@ -minitel.lua -tape-iofs.lua -fsmanager.service +getty.lua diff --git a/exec/init.lua b/exec/init.lua index f365cf6..c60aa7d 100644 --- a/exec/init.lua +++ b/exec/init.lua @@ -1,16 +1,26 @@ -xpcall(function() -os.setenv("PWD","/boot") -os.spawnfile("/boot/service/getty.lua") -coroutine.yield() -for k,v in pairs(fs.list("/dev/")) do - if v:sub(1,3) == "tty" then - dprint(tostring(io.input("/dev/"..v))) - dprint(tostring(io.output("/dev/"..v))) - print(_OSVERSION.." - "..tostring(math.floor(computer.totalMemory()/1024)).."K RAM") - os.spawnfile("/boot/exec/shell.lua") - end +if os.taskInfo(1) then + return false, "init already started" end +os.setenv("PWD","/boot") +io.input("/dev/null") +io.output("/dev/syslog") +local pids = {} +local function loadlist() + local f = io.open("/boot/cfg/init.txt","rb") + if not f then return false end + for line in f:read("*a"):gmatch("[^\r\n]+") do + dprint(line) + pids[line] = -1 + end + f:close() +end +loadlist() while true do + for k,v in pairs(pids) do + if not os.taskInfo(v) then + dprint("Starting service "..k) + pids[k] = os.spawnfile("/boot/service/"..k) + end + end coroutine.yield() end -end,function(e) dprint(e) end,"init")