code wiki / (root) / nx_wflow_completion_fixed_gate_t31.nx

nx_wflow_completion_fixed_gate_t31.nx source

↩ module page · 43 lines · 2159 B

1// Actual connector completion, qualified by an independent raw wait status. 2import "nx_wflow_engine_completion_t31.nx" 3const WC_SIGPIPE: i64=13 4func wc_signal_child() -> i64 { 5 if sys_default_signal(WC_SIGPIPE) != 0 { return 99 } 6 let fd: *i64=sys_mmap(16) as *i64 7 if sys_pipe2(fd,0) != 0 { return 98 } 8 let readfd: i64=fd[0]&0xffffffff 9 let writefd: i64=(fd[0]>>32)&0xffffffff 10 sys_close(readfd) 11 sys_write(writefd,"x" as *u8,1) 12 return 97 13} 14func main(argc: i64,argv: *i64) -> i64 { 15 if argc > 1 { 16 let mode: *u8=argv[1] as *u8 17 if mode[0] == (115 as u8) { return wc_signal_child() } 18 if mode[0] == (110 as u8) { return 7 } 19 return 0 20 } 21 let kid: i64=sys_fork() 22 if kid == 0 { sys_exit(wc_signal_child()); return 96 } 23 if kid < 0 { return 95 } 24 let st: *i64=sys_mmap(16) as *i64 25 let waited: i64=sys_wait4(kid,st,0) 26 p("CONTROL waited=" as *u8);pn(waited);p(" signal=" as *u8);pn(wait_term_signal(st[0]));p("\n" as *u8) 27 if waited != kid || wait_term_signal(st[0]) != WC_SIGPIPE { p("UNQUALIFIED signal fixture\n" as *u8);return 94 } 28 let path: *u8=sys_mmap(256) 29 var o: i64=wf_cat(path,0,"/tmp/nx_wflow_completion_t31_" as *u8) 30 o=wf_catn(path,o,kid);o=wf_cat(path,o,".conf" as *u8);path[o]=0 as u8 31 let row: *u8=sys_mmap(1024) 32 var r: i64=wf_cat(row,0,"self" as *u8) 33 row[r]=9 as u8;r=r+1;r=wf_cat(row,r,argv[0] as *u8) 34 row[r]=9 as u8;r=r+1;r=wf_cat(row,r,"GREEN" as *u8) 35 row[r]=10 as u8;row[r+1]=0 as u8;wf_append(path,row) 36 let cx: *i64=sys_mmap(32) as *i64;cx[3]=path as i64 37 let normal: i64=wf_exec_organ(cx,"self" as *u8,"ok" as *u8,"fixture" as *u8) 38 let nonzero: i64=wf_exec_organ(cx,"self" as *u8,"nonzero" as *u8,"fixture" as *u8) 39 let signaled: i64=wf_exec_organ(cx,"self" as *u8,"signal" as *u8,"fixture" as *u8) 40 p("COMPLETION normal=" as *u8);pn(normal);p(" nonzero=" as *u8);pn(nonzero);p(" signaled=" as *u8);pn(signaled);p("\n" as *u8) 41 if normal == 1 && nonzero == 0 && signaled == 0 { p("PASS qualified actual child completion\n" as *u8);return 0 } 42 p("FAIL terminated connector accepted\n" as *u8);return 1 43}