// Started by the packaged BusyBox init through /etc/inittab on a diskless guest. module main import os #include #include #include fn C.open(&char, int, ...) int fn C.dup2(int, int) int fn C.close(int) int fn C.reboot(int) int fn run(argv []string) !string { result := os.exec(argv) if result.exit_code != 0 { return error('${argv} exited ${result.exit_code}: ${result.output}') } return result.output.trim_space() } fn check(argv []string, expected string) ! { actual := run(argv)! if actual != expected { return error('${argv}: expected ${expected}, got ${actual}') } println('${argv} -> ${actual}') } fn verify() ! { for path in ['/sbin/init', '/bin/sh', '/bin/cat'] { if !os.is_link(path) || os.real_path(path) != '/bin/busybox' { return error('${path} must resolve to /bin/busybox') } } check(['/bin/busybox', 'uname', '-m'], 'x86_64')! check(['/bin/sh', '-c', r'echo $((6 * 7))'], '42')! check(['/bin/busybox', 'ash', '-c', r'echo $((3 * 7))'], '21')! check(['/bin/cat', '/etc/inittab'], '::sysinit:/busybox-probe')! println(run(['/bin/busybox', 'sha256sum', '/bin/busybox'])!) } fn main() { if os.getppid() != 1 || run(['/bin/busybox', 'uname', '-s']) or { '' } != 'Vinix' { eprintln('requires a Vinix guest with the probe started directly by init') exit(2) } fd := C.open(c'/dev/com1', C.O_WRONLY) if fd < 0 || C.dup2(fd, 1) < 0 || C.dup2(fd, 2) < 0 { exit(2) } if fd > 2 { C.close(fd) } verify() or { eprintln('VPAC BUSYBOX GUEST FAIL ${err}') C.reboot(C.RB_POWER_OFF) exit(1) } println('VPAC BUSYBOX GUEST PASS') C.reboot(C.RB_POWER_OFF) }