reboot: Implement -k in terms of env

kernel isn't special, beyond the sanity checks we do. Add it to the env
rather than pass it into write_nextboot().

Sponsored by:		Netflix
Reviewed by:		kevans, kib
Differential Revision:	https://reviews.freebsd.org/D43828
This commit is contained in:
Warner Losh 2024-02-12 11:45:54 -07:00
parent ecc834241f
commit 9dcf6cbd83

View file

@ -88,7 +88,7 @@ zfsbootcfg(const char *pool, bool force)
}
static void
write_nextboot(const char *fn, const char *env, const char *kernel, bool force)
write_nextboot(const char *fn, const char *env, bool force)
{
FILE *fp;
struct statfs sfs;
@ -112,12 +112,11 @@ write_nextboot(const char *fn, const char *env, const char *kernel, bool force)
fp = fopen(fn, "w");
if (fp == NULL)
E("Can't create %s to boot %s", fn, kernel);
E("Can't create %s", fn);
if (fprintf(fp,"%s%skernel=\"%s\"\n",
if (fprintf(fp,"%s%s",
supported ? "nextboot_enable=\"YES\"\n" : "",
env != NULL ? env : "",
kernel) < 0) {
env != NULL ? env : "") < 0) {
int e;
e = errno;
@ -175,7 +174,6 @@ main(int argc, char *argv[])
const char *user, *kernel = NULL;
char *env = NULL, *v;
if (strstr(getprogname(), "halt") != NULL) {
dohalt = true;
howto = RB_HALT;
@ -274,9 +272,10 @@ main(int argc, char *argv[])
errx(1, "%s is not a file", k);
free(k);
}
write_nextboot(PATH_NEXTBOOT, env, kernel, fflag);
add_env(&env, "kernel", kernel);
}
write_nextboot(PATH_NEXTBOOT, env, fflag);
/* Log the reboot. */
if (!lflag) {
if ((user = getlogin()) == NULL)