From 20e6de55ab1d426790ba858431f38b11e499c967 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Wed, 23 Mar 2022 13:26:06 +0200 Subject: 14585 loader: should preserve order of console device list Reviewed by: Richard Lowe Reviewed by: Garrett D'Amore Approved by: Garrett D'Amore --- usr/src/boot/Makefile.version | 2 +- usr/src/boot/common/console.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/usr/src/boot/Makefile.version b/usr/src/boot/Makefile.version index 3f11cd86eb..30812e2f31 100644 --- a/usr/src/boot/Makefile.version +++ b/usr/src/boot/Makefile.version @@ -34,4 +34,4 @@ LOADER_VERSION = 1.1 # Use date like formatting here, YYYY.MM.DD.XX, without leading zeroes. # The version is processed from left to right, the version number can only # be increased. -BOOT_VERSION = $(LOADER_VERSION)-2022.07.04.1 +BOOT_VERSION = $(LOADER_VERSION)-2022.07.11.1 diff --git a/usr/src/boot/common/console.c b/usr/src/boot/common/console.c index 0472ae7645..8ef67d53d6 100644 --- a/usr/src/boot/common/console.c +++ b/usr/src/boot/common/console.c @@ -185,6 +185,7 @@ cons_set(struct env_var *ev, int flags, const void *value) { int ret, cons; char *list, *tmp; + const char *console; if ((value == NULL) || (cons_check(value) == 0)) { /* @@ -201,9 +202,39 @@ cons_set(struct env_var *ev, int flags, const void *value) /* * build list of active consoles. + * Note, we need to preserve the ordered device list in 'value'. */ list = NULL; - for (cons = 0; consoles[cons] != NULL; cons++) { + console = value; + while (console[0] != '\0') { + /* Find corresponding entry from consoles array. */ + for (cons = 0; consoles[cons] != NULL; cons++) { + const char *name = consoles[cons]->c_name; + size_t len = strlen(name); + + if (strncmp(name, console, len) != 0) + continue; + len++; + if (console[len] == ',' || + console[len] == ' ' || + console[len] == '\0') { + break; + } + } + + /* Skip to delimiter */ + while (console[0] != ',' && + console[0] != ' ' && + console[0] != '\0') + console++; + /* Skip to next name */ + while (console[0] == ',' || console[0] == ' ') + console++; + + /* no such console? */ + if (consoles[cons] == NULL) + continue; + if ((consoles[cons]->c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) == (C_ACTIVEIN | C_ACTIVEOUT)) { if (list == NULL) { -- cgit v1.2.3