bootv2: bootstrap, vpn

This commit is contained in:
Mikaël Cluseau
2022-04-04 10:29:28 +02:00
parent 8506f8807d
commit 3c7d56ae48
17 changed files with 296 additions and 258 deletions

15
main.go
View File

@ -41,8 +41,21 @@ func newPipe() (io.ReadCloser, io.WriteCloser) {
}
func main() {
switch baseName := filepath.Base(os.Args[0]); baseName {
case "init":
runInit()
default:
log.Fatal("unknown sub-command: ", baseName)
}
}
func runInit() {
runtime.LockOSThread()
if pid := os.Getpid(); pid != 1 {
log.Fatal("init must be PID 1, not ", pid)
}
// move log to shio
go io.Copy(os.Stdout, stdout.NewReader())
log.SetOutput(stderr)
@ -134,8 +147,10 @@ mainLoop:
switch b[0] {
case 'o':
run("sync")
syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
case 'r':
run("sync")
syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
case 's':
for _, sh := range []string{"bash", "ash", "sh", "busybox"} {