Lorenz Brun | d67eb4f | 2023-04-11 16:03:31 +0200 | [diff] [blame] | 1 | package bootparam |
| 2 | |
| 3 | import ( |
| 4 | "regexp" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | var validTTYRegexp = regexp.MustCompile(`^[a-zA-Z0-9]+$`) |
| 9 | |
| 10 | // Consoles returns the set of consoles passed to the kernel, i.e. the values |
| 11 | // passed to the console= directive. It normalizes away any possibly present |
| 12 | // /dev/ prefix, returning values like ttyS0. It returns an empty set in case |
| 13 | // no valid console parameters exist. |
| 14 | func (p Params) Consoles() map[string]bool { |
| 15 | consoles := make(map[string]bool) |
| 16 | for _, pa := range p { |
| 17 | if pa.Param == "console" { |
| 18 | consoleParts := strings.Split(pa.Value, ",") |
| 19 | consoleName := strings.TrimPrefix(consoleParts[0], "/dev/") |
| 20 | if validTTYRegexp.MatchString(consoleName) { |
| 21 | consoles[consoleName] = true |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | return consoles |
| 26 | } |