code wiki / _hdl_build / nx_rollback_executor_t185.nx

nx_rollback_executor_t185.nx source

↩ module page · 22 lines · 1006 B

1import "nx_hostctl.nx" 2import "nx_file_install.nx" 3// Linux lseek whence values, not resource limits. 4const SEEK_END:i64=2 5const SEEK_SET:i64=0 6func main(argc:i64,argv:*i64)->i64{ 7 if argc!=2{return 2} 8 let sub:*u8=argv[1] as *u8 9 let want:*u8="gdeployrb@fixture";var k:i64=0 10 if fi_len(sub)!=fi_len(want){return 2} 11 while k<fi_len(want){if sub[k]!=want[k]{return 2};k=k+1} 12 let fd:i64=sys_openat_rd("rollback-live.path");if fd<0{return 3} 13 let n:i64=sys_lseek(fd,0,SEEK_END);if n<=0{sys_close(fd);return 3} 14 sys_lseek(fd,0,SEEK_SET);let path:*u8=sys_mmap(n+1) 15 let got:i64=sys_read(fd,path,n);sys_close(fd);if got!=n{return 3};path[n]=0 as u8 16 let prefix:*u8="/tmp/nishi-rollback-t185-";k=0 17 while prefix[k]!=0 as u8{if k>=n || path[k]!=prefix[k]{return 3};k=k+1} 18 if fi_path_valid(path)!=1{return 3} 19 let mark:i64=sys_openat_wr("rollback-executed.marker",MODE_0644) 20 if mark<0{return 3};sys_write(mark,"executed",8);sys_close(mark) 21 return cmd_gdeploy_rollback(path,"nishi-fixture-absent-daemon-t185") 22}