inits/pkg/vars/boot.go

33 lines
561 B
Go
Raw Permalink Normal View History

2018-07-06 08:07:37 +00:00
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
2018-07-06 08:25:00 +00:00
panic(fmt.Errorf("failed to read /proc/cmdline: %v", err))
2018-07-06 08:07:37 +00:00
}
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
}