From nobody Wed Jan  3 04:48:22 2024
X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T4cft43rRz54cZ6;
	Wed,  3 Jan 2024 04:48:22 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4T4cft2X0Qz3C0p;
	Wed,  3 Jan 2024 04:48:22 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1704257302;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=9WxOlzu2qZeMR6wdvuXY+xX2tRCFYD3RH7u0iGD1kto=;
	b=I0BkkPcm+CbsZZsZVaRkSZdnniw1lw5YSVKknCyuj9i0G3wEg0O0vlN6psxXNIlzUgBh8P
	0ZG++ZZ/Sury61y8fl2dQyGtxWkc/aGoZcW7GZ0J5aLXlDxGrEp2qmBaV3B3ySYZOX4diT
	0S89QTpt7pmLNjjzM7jZvPh+DHElLlzBuJe8iCrlL4etjnnwjt28XZ49QRxiibxdfozlw2
	yKGVxjrPLPs0IJMJ24NXk0atSkbiMNpZlyBTiH9oCjDTFehjpL8XpxZQEwJwPto3gGNYAr
	paeokItBqxUnsY4eYlNIOrZbwBP2Td1J2o6Wri16UZXy/P6uRVlUUhQIebxEJw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1704257302;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=9WxOlzu2qZeMR6wdvuXY+xX2tRCFYD3RH7u0iGD1kto=;
	b=CA5hgV+nl5Vs6pQjtCXNBTwIQ4bT17RpQxshFv65z8rNzePD1+wbURZQmZjgt7d39fG7P2
	tm+3BSAx5urlrTg4t8vyZgo1cpuwhcdXlbGDnrsm6YjZ3OuzxoR6MfQEiCa9KmqOx1FQyN
	ZPd5xQuuEfNLCF2DtkfkrXtN65W5Tz9VcVzvgvr3mnesmB9xS+qjsj/HvkxFRi324xwmXh
	Vh+PjIXbzB7ZaQeOFYvMNVWHU75xAm6oF41yCy4vOq4IU714q38/RdUVK+Fqk0/a+jezXn
	bPvgMItaz11ZizXMumPw82+4vhiOwX4BHQybQkNmsCSL5pI8SIvy8M7xa2Q5aQ==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704257302; a=rsa-sha256; cv=none;
	b=IZvu1bPxytf5hObyAGQO1+h+8gMoPQqCLu5eZ8/6xoIYGLYrjRW93UBIfNQwu5JiY1u8qi
	soIBUe/Q7LAzJu9Ey5Y0WOjWNCLrfHfyDV7yuxh57t/1Q+zdsu7IW8LMORjrynjSQmMxyE
	PYjGopOchG/3dH9KhXt3GXeUWi5+CRQK6d84AKDDSCpMNHpCNOnRiw/8Y8E7DIdGGYIBpV
	jhGPnKHbLwaynFWQvCz0yo29aVWf2CPZ5XBpfPivWmOLy00PZkR2j7qes9FUMF8Snppodl
	ey7BesDag0lasLgsIBQlTeIxly3BiG4qd9TIkgr0JBT4IgBDFe+0PG7PdVJBug==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(Client did not present a certificate)
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T4cft1d0nzWvG;
	Wed,  3 Jan 2024 04:48:22 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
	by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4034mMtG026344;
	Wed, 3 Jan 2024 04:48:22 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4034mMQO026341;
	Wed, 3 Jan 2024 04:48:22 GMT
	(envelope-from git)
Date: Wed, 3 Jan 2024 04:48:22 GMT
Message-Id: <202401030448.4034mMQO026341@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-branches@FreeBSD.org
From: Kyle Evans <kevans@FreeBSD.org>
Subject: git: 15b946de9917 - stable/14 - loader: lua: remove the
  default kernel if it doesn't exist
List-Id: Commits to the stable branches of the FreeBSD src repository <dev-commits-src-branches.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches
List-Help: <mailto:dev-commits-src-branches+help@freebsd.org>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-branches+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-branches+unsubscribe@freebsd.org>
Sender: owner-dev-commits-src-branches@freebsd.org
X-BeenThere: dev-commits-src-branches@freebsd.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kevans
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/14
X-Git-Reftype: branch
X-Git-Commit: 15b946de99174bef635b4a79e58d28f6c69825e5
Auto-Submitted: auto-generated

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