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