initrd/params.go

40 lines
696 B
Go
Raw Normal View History

2019-02-11 05:05:43 +00:00
package main
import (
2023-11-27 13:08:44 +00:00
"os"
2019-02-11 05:05:43 +00:00
"strings"
)
func param(name, defaultValue string) (value string) {
2023-11-27 13:08:44 +00:00
ba, err := os.ReadFile("/proc/cmdline")
2019-02-11 05:05:43 +00:00
if err != nil {
fatal("could not read /proc/cmdline: ", err)
}
2020-02-28 00:30:10 +00:00
prefixes := []string{
"direktil." + name + "=",
"dkl." + name + "=",
}
value = defaultValue
2019-02-11 05:05:43 +00:00
for _, part := range strings.Split(string(ba), " ") {
2020-02-28 00:30:10 +00:00
for _, prefix := range prefixes {
if strings.HasPrefix(part, prefix) {
value = strings.TrimSpace(part[len(prefix):])
}
2019-02-11 05:05:43 +00:00
}
}
2020-02-28 00:30:10 +00:00
return
}
func paramBool(name string, defaultValue bool) (value bool) {
defaultValueS := "false"
if defaultValue {
defaultValueS = "true"
}
return "true" == param(name, defaultValueS)
2019-02-11 05:05:43 +00:00
}