From 0c4c0b7957a152df86a8a764e74a4c01cbd486ea Mon Sep 17 00:00:00 2001 From: kevans Date: Thu, 28 Jun 2018 01:32:37 +0000 Subject: [PATCH] MFC r334882, r334884-r334885: loader(8) boot flag <-> environment fixes r334882: stand: Consolidate checking for boot flags driven by environment vars e.g. boot_mute, boot_single, boot_verbose, and friends; we checked for these in multiple places, consolidate into common/ and allow a setting of "NO" for any of these to turn them off. This allows systems with multiple loader.conf(5) or loader.conf(5) overlay systems to easily turn off variables in later processed files by setting it to NO. Reported by: Nick Wolff @ iXsystems Reviewed by: imp r334884: stand: Fix build after r334882 Not sure how this was not caught in Universe. r334885: stand: One more trivial consolidation (setting environment from howto) --- stand/common/boot.c | 26 ++++++++++++++++++++++++++ stand/common/bootstrap.h | 2 ++ stand/common/metadata.c | 9 ++------- stand/efi/loader/bootinfo.c | 13 +++---------- stand/efi/loader/main.c | 6 ++---- stand/i386/libi386/bootinfo.c | 12 ++---------- stand/userboot/userboot/bootinfo.c | 13 +++---------- 7 files changed, 40 insertions(+), 41 deletions(-) diff --git a/stand/common/boot.c b/stand/common/boot.c index 2b2a71d5936..2781778b462 100644 --- a/stand/common/boot.c +++ b/stand/common/boot.c @@ -32,6 +32,8 @@ __FBSDID("$FreeBSD$"); */ #include +#include +#include #include #include "bootstrap.h" @@ -158,6 +160,30 @@ autoboot_maybe() autoboot(-1, NULL); /* try to boot automatically */ } +int +bootenv_flags() +{ + int i, howto; + char *val; + + for (howto = 0, i = 0; howto_names[i].ev != NULL; i++) { + val = getenv(howto_names[i].ev); + if (val != NULL && strcasecmp(val, "no") != 0) + howto |= howto_names[i].mask; + } + return (howto); +} + +void +bootenv_set(int howto) +{ + int i; + + for (i = 0; howto_names[i].ev != NULL; i++) + if (howto & howto_names[i].mask) + setenv(howto_names[i].ev, "YES", 1); +} + static int autoboot(int timeout, char *prompt) { diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h index be9b98bf6e1..acd6b34e2e9 100644 --- a/stand/common/bootstrap.h +++ b/stand/common/bootstrap.h @@ -63,6 +63,8 @@ int parse(int *argc, char ***argv, const char *str); /* boot.c */ void autoboot_maybe(void); int getrootmount(char *rootdev); +int bootenv_flags(void); +void bootenv_set(int); /* misc.c */ char *unargv(int argc, char *argv[]); diff --git a/stand/common/metadata.c b/stand/common/metadata.c index 7be125c0025..94b7518bd7c 100644 --- a/stand/common/metadata.c +++ b/stand/common/metadata.c @@ -31,9 +31,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include -#include +#include #if defined(LOADER_FDT_SUPPORT) #include #endif @@ -100,7 +99,6 @@ md_getboothowto(char *kargs) char *cp; int howto; int active; - int i; /* Parse kargs */ howto = 0; @@ -153,10 +151,7 @@ md_getboothowto(char *kargs) } } - /* get equivalents from the environment */ - for (i = 0; howto_names[i].ev != NULL; i++) - if (getenv(howto_names[i].ev) != NULL) - howto |= howto_names[i].mask; + howto |= bootenv_flags(); #if defined(__sparc64__) if (md_bootserial() != -1) howto |= RB_SERIAL; diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index 4a4156658e0..43db6d7cfab 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -32,9 +32,8 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include -#include +#include #include #include #include @@ -72,15 +71,9 @@ bi_getboothowto(char *kargs) const char *sw; char *opts; char *console; - int howto, i; - - howto = 0; + int howto; - /* Get the boot options from the environment first. */ - for (i = 0; howto_names[i].ev != NULL; i++) { - if (getenv(howto_names[i].ev) != NULL) - howto |= howto_names[i].mask; - } + howto = bootenv_flags(); console = getenv("console"); if (console != NULL) { diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index 09ac1e0ccf1..ab310bbf0e2 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -549,9 +548,8 @@ main(int argc, CHAR16 *argv[]) } } } - for (i = 0; howto_names[i].ev != NULL; i++) - if (howto & howto_names[i].mask) - setenv(howto_names[i].ev, "YES", 1); + + bootenv_set(howto); /* * XXX we need fallback to this stuff after looking at the ConIn, ConOut and ConErr variables diff --git a/stand/i386/libi386/bootinfo.c b/stand/i386/libi386/bootinfo.c index c33cec7633a..0b69a9a21ec 100644 --- a/stand/i386/libi386/bootinfo.c +++ b/stand/i386/libi386/bootinfo.c @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include "bootstrap.h" #include "libi386.h" #include "btxv86.h" @@ -43,7 +42,6 @@ bi_getboothowto(char *kargs) char *curpos, *next, *string; int howto; int active; - int i; int vidconsole; /* Parse kargs */ @@ -96,10 +94,7 @@ bi_getboothowto(char *kargs) cp++; } } - /* get equivalents from the environment */ - for (i = 0; howto_names[i].ev != NULL; i++) - if (getenv(howto_names[i].ev) != NULL) - howto |= howto_names[i].mask; + howto |= bootenv_flags(); /* Enable selected consoles */ string = next = strdup(getenv("console")); @@ -134,11 +129,8 @@ bi_getboothowto(char *kargs) void bi_setboothowto(int howto) { - int i; - for (i = 0; howto_names[i].ev != NULL; i++) - if (howto & howto_names[i].mask) - setenv(howto_names[i].ev, "YES", 1); + bootenv_set(howto); } /* diff --git a/stand/userboot/userboot/bootinfo.c b/stand/userboot/userboot/bootinfo.c index 289ca071fe8..29a94af1752 100644 --- a/stand/userboot/userboot/bootinfo.c +++ b/stand/userboot/userboot/bootinfo.c @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include "bootstrap.h" #include "libuserboot.h" @@ -43,7 +42,6 @@ bi_getboothowto(char *kargs) char *curpos, *next, *string; int howto; int active; - int i; int vidconsole; /* Parse kargs */ @@ -96,10 +94,8 @@ bi_getboothowto(char *kargs) cp++; } } - /* get equivalents from the environment */ - for (i = 0; howto_names[i].ev != NULL; i++) - if (getenv(howto_names[i].ev) != NULL) - howto |= howto_names[i].mask; + + howto |= bootenv_flags(); /* Enable selected consoles */ string = next = strdup(getenv("console")); @@ -134,11 +130,8 @@ bi_getboothowto(char *kargs) void bi_setboothowto(int howto) { - int i; - for (i = 0; howto_names[i].ev != NULL; i++) - if (howto & howto_names[i].mask) - setenv(howto_names[i].ev, "YES", 1); + bootenv_set(howto); } /* -- 2.45.0