code wiki / _hdl_build / nx_snapfeed.nx
nx_snapfeed.nx
buildroot/runtime/_hdl_build/nx_snapfeed.nx
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
imports: nx_syscalls.nx
imported by: nx_mgmt_snapshot_run.nxnx_snapfeed_gate.nx
structs
| none |
consts
| none |
functions
| 17 | func sf_digit(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 } |
| 19 | func sf_atoi(b: *u8, off: i64, len: i64) -> i64 |
| 27 | func sf_contains_seg(b: *u8, lo: i64, hi: i64, needle: *u8) -> i64 |
| 43 | func sf_contains(b: *u8, n: i64, needle: *u8) -> i64 { return sf_contains_seg(b, 0, n, needle) } |
| 46 | func sf_parse_stat(buf: *u8, n: i64, out3: *i64) -> i64 |
| 87 | func sf_is_leader(pid: i64, sid: i64) -> i64 { if pid == sid { return 1 } return 0 } called by 1: main |
| 90 | func sf_count_restarts(log: *u8, n: i64, key: *u8) -> i64 |