Initial commit

This commit is contained in:
Mikaël Cluseau
2018-07-06 19:07:37 +11:00
commit 2de2a4d0f6
25 changed files with 2050 additions and 0 deletions

32
pkg/vars/boot.go Normal file
View File

@ -0,0 +1,32 @@
package vars
import (
"bytes"
"fmt"
"io/ioutil"
)
var (
bootVarPrefix = []byte("direktil.var.")
)
func BootArgs() [][]byte {
ba, err := ioutil.ReadFile("/proc/cmdline")
if err != nil {
// should not happen
panic(fmt.Errorf("failed to read /proc/cmdline: ", err))
}
return bytes.Split(ba, []byte{' '})
}
func BootArgValue(prefix, defaultValue string) string {
prefixB := []byte("direktil." + prefix + "=")
for _, ba := range BootArgs() {
if bytes.HasPrefix(ba, prefixB) {
return string(ba[len(prefixB):])
}
}
return defaultValue
}