mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
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 Differential Revision: https://reviews.freebsd.org/D42967
This commit is contained in:
parent
a206524709
commit
d04415c520
|
@ -201,17 +201,18 @@ function core.kernelList()
|
||||||
return core.cached_kernels
|
return core.cached_kernels
|
||||||
end
|
end
|
||||||
|
|
||||||
local k = loader.getenv("kernel")
|
local default_kernel = loader.getenv("kernel")
|
||||||
local v = loader.getenv("kernels")
|
local v = loader.getenv("kernels")
|
||||||
local autodetect = loader.getenv("kernels_autodetect") or ""
|
local autodetect = loader.getenv("kernels_autodetect") or ""
|
||||||
|
|
||||||
local kernels = {}
|
local kernels = {}
|
||||||
local unique = {}
|
local unique = {}
|
||||||
local i = 0
|
local i = 0
|
||||||
if k ~= nil then
|
|
||||||
|
if default_kernel then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
kernels[i] = k
|
kernels[i] = default_kernel
|
||||||
unique[k] = true
|
unique[default_kernel] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if v ~= nil then
|
if v ~= nil then
|
||||||
|
@ -239,6 +240,8 @@ function core.kernelList()
|
||||||
return core.cached_kernels
|
return core.cached_kernels
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local present = {}
|
||||||
|
|
||||||
-- Automatically detect other bootable kernel directories using a
|
-- Automatically detect other bootable kernel directories using a
|
||||||
-- heuristic. Any directory in /boot that contains an ordinary file
|
-- heuristic. Any directory in /boot that contains an ordinary file
|
||||||
-- named "kernel" is considered eligible.
|
-- named "kernel" is considered eligible.
|
||||||
|
@ -267,8 +270,25 @@ function core.kernelList()
|
||||||
unique[file] = true
|
unique[file] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
present[file] = true
|
||||||
|
|
||||||
::continue::
|
::continue::
|
||||||
end
|
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
|
core.cached_kernels = kernels
|
||||||
return core.cached_kernels
|
return core.cached_kernels
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue