talos/internal/pkg/kernel/kernel.go
Andrew Rynhard ee226dddac
chore: enforce commit and license policies (#304)
Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
2019-01-13 16:10:49 -08:00

31 lines
772 B
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package kernel
import (
"io/ioutil"
"strings"
)
// ParseProcCmdline parses /proc/cmdline and returns a map reprentation of the
// kernel parameters.
func ParseProcCmdline() (cmdline map[string]string, err error) {
cmdline = map[string]string{}
cmdlineBytes, err := ioutil.ReadFile("/proc/cmdline")
if err != nil {
return
}
line := strings.TrimSuffix(string(cmdlineBytes), "\n")
arguments := strings.Split(line, " ")
for _, a := range arguments {
kv := strings.Split(a, "=")
if len(kv) == 2 {
cmdline[kv[0]] = kv[1]
}
}
return cmdline, err
}