github.com/hugelgupf/u-root@v0.0.0-20191023214958-4807c632154c/cmds/exp/cpu/init.go (about) 1 // Copyright 2018-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This is init code for the case that cpu finds itself as pid 1. 6 // This is duplicative of the real init, but we're implementing it 7 // as a duplicate so we can get some idea of: 8 // what an init package should have 9 // what an init interface should have 10 // So we take a bit of duplication now to better understand these 11 // things. We also assume for now this is a busybox environment. 12 // It is unusual (I guess?) for cpu to be an init in anything else. 13 // So far, the case for an init pkg is not as strong as I thought 14 // it might be. 15 package main 16 17 import ( 18 "log" 19 "syscall" 20 21 "github.com/u-root/u-root/pkg/libinit" 22 ) 23 24 func cpuSetup() error { 25 log.Printf("Welcome to Plan 9(tm)!") 26 libinit.SetEnv() 27 libinit.CreateRootfs() 28 libinit.NetInit() 29 return nil 30 } 31 32 func cpuDone(c chan uint) { 33 // We need to reap all children before exiting. 34 log.Printf("init: Waiting for orphaned children") 35 procs := libinit.WaitOrphans() 36 log.Printf("cpu: All commands exited") 37 log.Printf("cpu: Syncing filesystems") 38 syscall.Sync() 39 c <- procs 40 }