Page MenuHomeFreeBSD

kenv: allow listing of static kernel environments
ClosedPublic

Authored by kevans on Jun 20 2021, 8:57 PM.

Details

Summary

The early environment is typically cleared, so these new options
need the PRESERVE_EARLY_KENV kernel config(8) option. These environments
are reported as missing by kenv(1) if the option is not present in the
running kernel.

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Dump seems overloaded here. It was confusing before and this compounds the confusion.

bin/kenv/kenv.1
53

Dump is a terrible word. Does this mean discard or list? I'd suggest replacing the ambiguous term with whichever this is.

kevans retitled this revision from kenv: allow dumping of static kernel environments to kenv: allow listing of static kernel environments.Jun 21 2021, 3:19 AM
kevans edited the summary of this revision. (Show Details)
sys/kern/kern_environment.c
181

I think it might be a bit clearer to rewrite this as a switch on the what. I think it's then more obvious that your MPASS is really an '_assert_unreachable()'. Looking at this even further though, I think I'd really like to just split out this early section into a helper function:

static int
kenv_dump(char **envp, int what, char *value, int len)
{
   char *senv;

   senv = **envp;
   ....
}

And then in sys_kenv() you add this to the start of the switch statement below:

    switch (uap->what) {
    case KENV_DUMP:
        return (kenv_dump(kenvp, uap->what, uap->value, uap->len));
    case KENV_DUMP_LOADER:
    case KENV_DUMP_STATIC:
#ifdef PRESERVE_EARLY_KENV
        return (kenv_dump(uap->what == KENV_DUMP_LOADER ? &md_envp : &kern_envp,
            uap->what, uap->value, uap->len);
#else
        return (ENOENT);
#endif
`
kevans marked an inline comment as done.
kevans edited the summary of this revision. (Show Details)

Address commentary from jhb

This revision is now accepted and ready to land.Jun 27 2021, 6:40 AM