blob: bbb4faef35c918967ffbd5fe5211685323119103 [file] [log] [blame]
Lorenz Brund67eb4f2023-04-11 16:03:31 +02001package bootparam
2
3import (
4 "regexp"
5 "strings"
6)
7
8var 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.
14func (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}