code wiki / _hdl_build / nx_snapfeed.nx

nx_snapfeed.nx

buildroot/runtime/_hdl_build/nx_snapfeed.nx

4623 B103 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_snapfeed.nx -- the /proc + supervisor.log PARSE logic that produces the FEED consumed by nx_mgmt_snapshot's ss_synth (which in turn emits the SUP/SVC snapshot /api/health reads). This is the DATA-gathering parse tier of the R1b producer: pid/ppid/sid extraction + service identification + crash-loop restart counting. PURE + gateable (sf_*, imports only nx_syscalls); the LIVE /proc directory enumeration reuses nx_hostctl's existing proc-scan (anti-reinvention) -- this organ is the parse logic that scan will call per pid. TWO hard-won correctness lessons are encoded here (both from real incidents): 1) IDENTIFY A SERVICE BY ITS FULL /proc/<pid>/cmdline, NEVER by `comm`. The kernel truncates comm to 15 chars (TASK_COMM_LEN-1), so `nx_gallery_gateway.elf` (22 ch) shows as `nx_gallery_gate` -- a comm match SILENTLY MISSES it (this exact bug = the 2026-06-29 gallery-login disaster: a kill matched nothing while reporting success). sf_contains over the full cmdline blob is the fix. 2) PARSE /proc/<pid>/stat ROBUSTLY: field 2 (comm) is wrapped in parens and MAY CONTAIN SPACES AND PARENS, so a naive space-split corrupts ppid/sid. We anchor on the LAST ')' then read fields [state ppid pgrp sid]. license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_snapfeed.nx nx_mgmt_snapshot_run.nx nx_snapfeed_gate.nx

imports: nx_syscalls.nx

imported by: nx_mgmt_snapshot_run.nxnx_snapfeed_gate.nx

structs

none

consts

none

functions

17func sf_digit(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 }
19func sf_atoi(b: *u8, off: i64, len: i64) -> i64
called by 1: sf_parse_stat calls 1: sf_digit
27func sf_contains_seg(b: *u8, lo: i64, hi: i64, needle: *u8) -> i64
43func sf_contains(b: *u8, n: i64, needle: *u8) -> i64 { return sf_contains_seg(b, 0, n, needle) }
called by 3: msr_is_supmainmain calls 1: sf_contains_seg
46func sf_parse_stat(buf: *u8, n: i64, out3: *i64) -> i64
called by 2: mainmain calls 2: sf_digitsf_atoi
87func sf_is_leader(pid: i64, sid: i64) -> i64 { if pid == sid { return 1 } return 0 }
called by 1: main
90func sf_count_restarts(log: *u8, n: i64, key: *u8) -> i64
called by 2: mainmain calls 1: sf_contains_seg