code wiki / _hdl_build / nx_init_live.nx
nx_init_live.nx
buildroot/runtime/_hdl_build/nx_init_live.nx
about
nx_init_live.nx -- GATE: REAL process supervision. Reworks nx_init (dependency-ordered start, Kahn topo) +
nx_supervise (restart-with-give-up-cap) onto ACTUAL forked child processes with wait4(WNOHANG) liveness -- closing
the INIT-SERVICES census gap ("real fork/wait liveness wiring"). Grounded on the banked field research (pp_init/
pp_wait/pp_zombie/pp_systemd/pp_runit): PID1 reaps children; a supervisor detects death via wait4 and restarts with
backoff + a give-up cap (no restart storm). The liveness primitive is proven (nx_initlive_probe: real fork + wait4
WNOHANG detects death w/ exit code, distinguishes alive).
Services (dependency-ordered): base(healthy) <- worker(crashy, the cap demo) & logger(healthy).
T1 dependency-ordered start (topo): base starts before its dependents; order respected.
T2 healthy services (base+logger) stay ALIVE with 0 restarts -- wait4 WNOHANG reported alive every tick (REAL).
T3 the crashy worker is DETECTED dead + re-forked until the cap -> gaveup (real death-detection + restart loop).
T4 teeth: the worker's (cap+1) spawns are ALL DISTINCT pids (genuine new processes) + restarts NEVER exceed cap.
T5 teardown: the healthy children are blocking-reaped (real pids, no zombie left).
expect_exit: 0 Sovereign: nx_syscalls (fork/wait4/poll). NEVER-BRICK: forks+reaps userspace procs, 0 firmware.
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 15 | const ST_MAGIC_1500: i64 = 1500 |
| 22 | const MAXD: i64 = 4 |
| 23 | const ST_RUNNING: i64 = 1 |
| 24 | const ST_GAVEUP: i64 = 2 |
| 25 | const K_HEALTHY: i64 = 0 |
| 26 | const K_CRASHY: i64 = 1 |
functions
| 17 | func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 18 | func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 } |
| 19 | func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c } |
| 20 | func sleep_ms(ms: i64) -> i64 { sys_poll(0 as *u8, 0, ms); return 0 } |
| 29 | func nx_topo(ndep: *i64, dep: *i64, N: i64, order: *i64) -> i64 |
| 46 | func nx_order_ok(order: *i64, oc: i64, ndep: *i64, dep: *i64, N: i64) -> i64 |
| 56 | func spawn(kind: *i64, pid: *i64, i: i64) -> i64 |
| 66 | func main() -> i64 |