bootv2: bootstrap, vpn
This commit is contained in:
15
main.go
15
main.go
@ -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"} {
|
||||
|
Reference in New Issue
Block a user