Date: Wed, 3 Jan 2024 04:48:22 GMT From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 15b946de9917 - stable/14 - loader: lua: remove the default kernel if it doesn't exist Message-ID: <202401030448.4034mMQO026341@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=15b946de99174bef635b4a79e58d28f6c69825e5 commit 15b946de99174bef635b4a79e58d28f6c69825e5 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2023-12-13 16:52:14 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2024-01-03 04:47:21 +0000 loader: lua: remove the default kernel if it doesn't exist The `kernel` env var provides the default kernel, usually "kernel". It may be the case that the user doesn't have a "kernel" kernel, just "kernel.*" kernels, but have left `kernel` to the default because we autodetect entries by default anyways. If we're doing autodetection, take note of whether the default kernel exists or not and remove it from the list if it doesn't and we had found any other kernels. We avoid it in the #kernels == 1 case because something fishy has likely happened and we should just trust the configuration. Reviewed by: imp, manu (cherry picked from commit d04415c520b031fb8eb93cb252e4acee66149c87) --- stand/lua/core.lua | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/stand/lua/core.lua b/stand/lua/core.lua index 358705ac7ace..747f8c1f0fcf 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -204,17 +204,18 @@ function core.kernelList() return core.cached_kernels end - local k = loader.getenv("kernel") + local default_kernel = loader.getenv("kernel") local v = loader.getenv("kernels") local autodetect = loader.getenv("kernels_autodetect") or "" local kernels = {} local unique = {} local i = 0 - if k ~= nil then + + if default_kernel then i = i + 1 - kernels[i] = k - unique[k] = true + kernels[i] = default_kernel + unique[default_kernel] = true end if v ~= nil then @@ -242,6 +243,8 @@ function core.kernelList() return core.cached_kernels end + local present = {} + -- Automatically detect other bootable kernel directories using a -- heuristic. Any directory in /boot that contains an ordinary file -- named "kernel" is considered eligible. @@ -270,8 +273,25 @@ function core.kernelList() unique[file] = true end + present[file] = true + ::continue:: end + + -- If we found more than one kernel, prune the "kernel" specified kernel + -- off of the list if it wasn't found during traversal. If we didn't + -- actually find any kernels, we just assume that they know what they're + -- doing and leave it alone. + if default_kernel and not present[default_kernel] and #kernels > 1 then + for i = 1, #kernels do + if i == #kernels then + kernels[i] = nil + else + kernels[i] = kernels[i + 1] + end + end + end + core.cached_kernels = kernels return core.cached_kernels end
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401030448.4034mMQO026341>