nx_proc_kill.nx source
↩ module page · 34 lines · 2146 B
1// nx_proc_kill.nx -- sovereign "kill by FULL /proc/<pid>/cmdline" CLI (retires pkill). Now composes the canonical
2// nx_proc_ctl, FIXING the old /proc/<pid>/comm match that truncated long names to 15 chars and silently matched
3// nothing (the 2026-06-29 gallery-login disaster). Target = argv[1], else the staging file nxpk_target.txt (the WOMB
4// drops args, so that path stays). Refuses an empty target. Reports the HONEST killed count. license_tier: ORIGINAL
5import "nx_proc_ctl.nx"
6import "nx_gate.nx"
7
8// read the staging file, strip trailing CR/NL; returns target length (0 if absent/empty)
9func pk_read_target(out: *u8) -> i64 {
10 let tfd: i64 = sys_openat_rd("/mnt/c/Users/elder/AppData/Local/Temp/nxpk_target.txt" as *u8)
11 if tfd < 0 { return 0 }
12 let tr: i64 = sys_read(tfd, out, 60); sys_close(tfd)
13 if tr <= 0 { return 0 }
14 var k: i64 = 0
15 while k < tr { let c: i64 = out[k] as i64; if c==10 { out[k]=0 as u8 } if c==13 { out[k]=0 as u8 } k=k+1 }
16 out[tr] = 0 as u8
17 var len: i64=0; while out[len]!=(0 as u8){len=len+1}
18 return len
19}
20
21func main(argc: i64, argv: *i64) -> i64 {
22 let target: *u8 = sys_mmap(256)
23 var have: i64 = 0
24 if argc >= 2 { let a: *u8=argv[1] as *u8; var i: i64=0; while a[i]!=(0 as u8){ target[i]=a[i]; i=i+1 } target[i]=0 as u8; if target[0]!=(0 as u8){ have=1 } }
25 if have == 0 { if pk_read_target(target) > 0 { have=1 } }
26 if have == 0 { gw("nx_proc_kill: no target (argv[1] or nxpk_target.txt) -- refusing (an empty target would match every process)\n" as *u8); sys_exit(1); return 1 }
27 var sig: i64 = 9
28 if argc >= 3 { let s: *u8=argv[2] as *u8; var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let d: i64=s[i] as i64; if d>=48 { if d<=57 { v=v*10+(d-48) } } i=i+1 } if v>0 { sig=v } }
29 gw("nx_proc_kill: target=/" as *u8); gw(target); gw(" (full-cmdline match, sig=" as *u8); gn(sig); gw(")\n" as *u8)
30 let killed: i64 = nx_pctl_kill_by_cmdline(target, sig)
31 gw(" killed=" as *u8); gn(killed); gw("\n" as *u8)
32 if killed <= 0 { gw(" KILLED 0 -- nothing matched (op did nothing)\n" as *u8); sys_exit(2); return 2 }
33 sys_exit(0); return 0
34}