Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110618935
D32477.id97973.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D32477.id97973.diff
View Options
Index: sys/kern/kern_environment.c
===================================================================
--- sys/kern/kern_environment.c
+++ sys/kern/kern_environment.c
@@ -59,6 +59,8 @@
static char *_getenv_dynamic_locked(const char *name, int *idx);
static char *_getenv_dynamic(const char *name, int *idx);
+static char *_getenv_static_from(char *chkenv, const char *name);
+static int kenv_to_bool(const char *val, bool *data);
static char *kenv_acquire(const char *name);
static void kenv_release(const char *buf);
@@ -77,6 +79,7 @@
char *md_envp;
static int md_env_len;
static int md_env_pos;
+bool loader_hints_disabled;
static char *kernenv_next(char *);
@@ -354,7 +357,15 @@
kern_envp[1] = '\0';
}
}
- if (getenv_is_true("static_hints.disabled")) {
+
+ /*
+ * Nothing to act on here, it'll fail if it's unset and it will
+ * fail if it's malformed. The former is not an error here, and
+ * the latter case will already helpfully print an error.
+ */
+ (void)kenv_to_bool(_getenv_static_from(static_hints,
+ "loader_hints.disabled"), &loader_hints_disabled);
+ if (!loader_hints_disabled && getenv_is_true("static_hints.disabled")) {
static_hints[0] = '\0';
static_hints[1] = '\0';
}
@@ -387,6 +398,11 @@
goto sanitize;
}
*eqpos = 0;
+
+ if (loader_hints_disabled &&
+ strncmp(cp, "hint.", 5) == 0)
+ goto sanitize;
+
/*
* De-dupe the environment as we go. We don't add the
* duplicated assignments because config(8) will flip
@@ -985,6 +1001,24 @@
return (0);
}
+static int
+kenv_to_bool(const char *val, bool *data)
+{
+ int ret;
+
+ ret = 0;
+ if (val == NULL)
+ return (EINVAL);
+
+ if ((strcmp(val, "1") == 0) || (strcasecmp(val, "true") == 0))
+ *data = true;
+ else if ((strcmp(val, "0") == 0) || (strcasecmp(val, "false") == 0))
+ *data = false;
+ else
+ ret = EDOM;
+ return (ret);
+}
+
/*
* Return a boolean value from an environment variable. This can be in
* numerical or string form, i.e. "1" or "true".
@@ -999,23 +1033,17 @@
return (0);
val = kern_getenv(name);
- if (val == NULL)
- return (0);
+ ret = kenv_to_bool(val, data);
+ freeenv(val);
- if ((strcmp(val, "1") == 0) || (strcasecmp(val, "true") == 0)) {
- *data = true;
- ret = 1;
- } else if ((strcmp(val, "0") == 0) || (strcasecmp(val, "false") == 0)) {
- *data = false;
- ret = 1;
- } else {
+ if (ret == EDOM) {
/* Spit out a warning for malformed boolean variables. */
printf("Environment variable %s has non-boolean value \"%s\"\n",
name, val);
}
- freeenv(val);
- return (ret);
+ /* Returns non-zero if result is valid. */
+ return (ret == 0 ? 1 : 0);
}
/*
Index: sys/kern/subr_hints.c
===================================================================
--- sys/kern/subr_hints.c
+++ sys/kern/subr_hints.c
@@ -177,7 +177,8 @@
switch (fbacklvl) {
case FBACK_MDENV:
fbacklvl++;
- if (_res_checkenv(md_envp)) {
+ if (!loader_hints_disabled &&
+ _res_checkenv(md_envp)) {
hintp = md_envp;
break;
}
Index: sys/sys/kenv.h
===================================================================
--- sys/sys/kenv.h
+++ sys/sys/kenv.h
@@ -52,6 +52,7 @@
extern struct mtx kenv_lock;
extern char *kern_envp;
extern char *md_envp;
+extern bool loader_hints_disabled;
extern char static_env[];
extern char static_hints[]; /* by config for now */
Index: usr.sbin/config/config.5
===================================================================
--- usr.sbin/config/config.5
+++ usr.sbin/config/config.5
@@ -23,7 +23,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 28, 2021
+.Dd November 3, 2021
.Dt CONFIG 5
.Os
.Sh NAME
@@ -131,8 +131,8 @@
environment.
Disabling the
.Xr loader 8
-should be done with caution and due consideration for whether or not it supplies
-environment variables needed for properly booting the system.
+environment should be done with caution and due consideration for whether or not
+it supplies environment variables needed for properly booting the system.
.Pp
.Va static_env.disabled=1
may be specified in the
@@ -209,6 +209,16 @@
the dynamic environment.
The dynamic environment will then be used for all searches of hints.
.Pp
+.Va loader_hints.disabled=1
+may be specified in the compiled-in environment to disable use of hints from
+the
+.Xr loader 8
+environment.
+Disabling hints from the
+.Xr loader 8
+environment should be done with caution and due consideration for whether or not
+it supplies hints needed for properly booting the system.
+.Pp
.Va static_hints.disabled=1
may be specified in either a compiled-in environment or the
.Xr loader 8
@@ -216,6 +226,9 @@
This option has no effect if specified in any environment after the
.Xr loader 8
environment is processed.
+This option also has no effect if loader hints have been disabled by the static
+environment setting
+.Va loader_hints.disabled=1 .
.Pp
The file
.Ar filename
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 22, 12:01 AM (2 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16763111
Default Alt Text
D32477.id97973.diff (4 KB)
Attached To
Mode
D32477: kenv: allow static hints to disable loader hints
Attached
Detach File
Event Timeline
Log In to Comment