aboutsummaryrefslogtreecommitdiff
path: root/bin/kenv
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2021-06-20 19:36:10 +0000
committerKyle Evans <kevans@FreeBSD.org>2021-07-19 04:06:19 +0000
commitdb0f26439357b78863e61985acd1e5acf75ce73d (patch)
tree9a30a6481206e81ec1b726294398fdd41c88896c /bin/kenv
parent7a129c973b5ba0fa916dfa658d523bec66dbd02d (diff)
Diffstat (limited to 'bin/kenv')
-rw-r--r--bin/kenv/kenv.118
-rw-r--r--bin/kenv/kenv.c38
2 files changed, 47 insertions, 9 deletions
diff --git a/bin/kenv/kenv.1 b/bin/kenv/kenv.1
index 0cadbefb41b3..980bec117515 100644
--- a/bin/kenv/kenv.1
+++ b/bin/kenv/kenv.1
@@ -32,6 +32,7 @@
.Nd list or modify the kernel environment
.Sh SYNOPSIS
.Nm
+.Op Fl l | s
.Op Fl hNq
.Nm
.Op Fl qv
@@ -45,6 +46,23 @@ The
.Nm
utility will list all variables in the kernel environment if
invoked without arguments.
+.Pp
+If the
+.Fl l
+option is specified, then the static environment provided by
+.Xr loader 8
+will be listed instead.
+Similarly, the
+.Fl s
+option will list the static environment defined by the kernel config.
+Both of the
+.Fl l
+and
+.Fl s
+options are dependent on the kernel being configured to preserve early kernel
+environments.
+The default kernel configuration does not preserve these environments.
+.Pp
If the
.Fl h
option is specified, it will limit the report to kernel probe hints.
diff --git a/bin/kenv/kenv.c b/bin/kenv/kenv.c
index 77caeaf5bca2..ecf30ee6b617 100644
--- a/bin/kenv/kenv.c
+++ b/bin/kenv/kenv.c
@@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/sysctl.h>
#include <err.h>
+#include <errno.h>
#include <kenv.h>
#include <stdio.h>
#include <stdlib.h>
@@ -36,14 +37,16 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
static void usage(void);
-static int kdumpenv(void);
+static int kdumpenv(int dump_type);
static int kgetenv(const char *);
static int ksetenv(const char *, char *);
static int kunsetenv(const char *);
static int hflag = 0;
+static int lflag = 0;
static int Nflag = 0;
static int qflag = 0;
+static int sflag = 0;
static int uflag = 0;
static int vflag = 0;
@@ -51,7 +54,7 @@ static void
usage(void)
{
(void)fprintf(stderr, "%s\n%s\n%s\n",
- "usage: kenv [-hNq]",
+ "usage: kenv [-l|-s] [-hNq]",
" kenv [-qv] variable[=value]",
" kenv [-q] -u variable");
exit(1);
@@ -65,17 +68,23 @@ main(int argc, char **argv)
val = NULL;
env = NULL;
- while ((ch = getopt(argc, argv, "hNquv")) != -1) {
+ while ((ch = getopt(argc, argv, "hlNqsuv")) != -1) {
switch (ch) {
case 'h':
hflag++;
break;
+ case 'l':
+ lflag++;
+ break;
case 'N':
Nflag++;
break;
case 'q':
qflag++;
break;
+ case 's':
+ sflag++;
+ break;
case 'u':
uflag++;
break;
@@ -100,12 +109,23 @@ main(int argc, char **argv)
}
if ((hflag || Nflag) && env != NULL)
usage();
+ if (lflag && sflag)
+ usage();
if (argc > 0 || ((uflag || vflag) && env == NULL))
usage();
if (env == NULL) {
- error = kdumpenv();
- if (error && !qflag)
- warn("kdumpenv");
+ if (lflag)
+ error = kdumpenv(KENV_DUMP_LOADER);
+ else if (sflag)
+ error = kdumpenv(KENV_DUMP_STATIC);
+ else
+ error = kdumpenv(KENV_DUMP);
+ if (error && !qflag) {
+ if (errno == ENOENT)
+ warnx("requested environment is unavailable");
+ else
+ warn("kdumpenv");
+ }
} else if (val == NULL) {
if (uflag) {
error = kunsetenv(env);
@@ -125,12 +145,12 @@ main(int argc, char **argv)
}
static int
-kdumpenv(void)
+kdumpenv(int dump_type)
{
char *buf, *bp, *cp;
int buflen, envlen;
- envlen = kenv(KENV_DUMP, NULL, NULL, 0);
+ envlen = kenv(dump_type, NULL, NULL, 0);
if (envlen < 0)
return (-1);
for (;;) {
@@ -138,7 +158,7 @@ kdumpenv(void)
buf = calloc(1, buflen + 1);
if (buf == NULL)
return (-1);
- envlen = kenv(KENV_DUMP, NULL, buf, buflen);
+ envlen = kenv(dump_type, NULL, buf, buflen);
if (envlen < 0) {
free(buf);
return (-1);