blob: e90bde7e408b621bb720e100c0944a003e44cc80 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Lorenz Brund67eb4f2023-04-11 16:03:31 +02004package bootparam
5
6import (
7 "regexp"
8 "strings"
9)
10
11var 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.
17func (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}