From nobody Wed Dec 13 16:52:20 2023 X-Original-To: dev-commits-src-main@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 4Sr1jx2V8kz54282; Wed, 13 Dec 2023 16:52:21 +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 4Sr1jw71k0z3fmK; Wed, 13 Dec 2023 16:52:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702486341; 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=/HiX+whBC6QfL645UiWd/6yRxofWwt/imPV9sLBp7VA=; b=Ahaa/WuPai4WC8Mq2fD1gvUnzGN4ZJf8TWX9zOV0d2lI3L2E1uJDZwENJJNzFtu6rgx+aZ a2WZ5Qs/4kp1wtM/0SYVVyBTXjoiGYOFFzlbFiSAwSYa1RBdIF/FZcyO6e/m19KRaoN2pG rw4MfPfHIzo3qzBIFX1TRQjTM4b3w+eOyRlh7H0y9qzVVAEf2oVPvF3E1TqNqRa2+adVD9 7Jc8GeEsMyVJcPzIP6zUTy4DAqZNEGk+zG4qDRp3+FJXUHtWKaIxDToPwtTmeT9GWW2qDw WHoXgs3DL1BhD83WCrpMfCC8zruwz1tuxQW6idzAsSSKsYarVhkqjZyWAZWAbQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702486341; a=rsa-sha256; cv=none; b=B+cbMm7vXnpb0pQerBLObEAiNM8H2o2PQw4kNLSULjk38iZJbTczS/ycISmiYkMD/ZqFiu iD+vZ54To255AXMuvrsu3oggpkW/ul+pGiDabWNwd6Runi195D8SHminSiZsS1ZRLofub5 kisiImfyb5UjDCeS7Wn+PAQqQZEIdwmRxSXY4bVahZc49jM+CuhpfZPBZgD1D8U3mp6LTJ myVe3fYRraupzboz1Y9evYZpKld8FVUQxbUVspC9jiGf5DR+luoSK9ZOHNdflPMwhdTy4d 2BzAVYr1/OwZRfYaOHpMkvI6kW1vQL61FsRejM32mWOz+83E48WFUz6Fz5G+hw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702486341; 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=/HiX+whBC6QfL645UiWd/6yRxofWwt/imPV9sLBp7VA=; b=SBTRfTXhnCyl8y+vq6sHcomszM9I/1mfkK8Niu3HY7MYh9vdPjmUJrfSLMGfWSBkVG9paW 7SGRYAPLgu+6wQ41WKSRUhJ7rVOmvwjxN+tE9AZCaxXp8RW9furMLFfz+CqgTaSh2xZyu7 avzTLB2rKvizU0iylCT4a+GJLHWggXLcEPbcHBDVRdURzPSK3fpp8sGryYCFRsFjAsdLXL mca9XiiJphiDkprgBiRI9wzr0slcWGSDqom/sB9SoTE5QXZYc1bYoi0i/7lWQRVLW5m0Jm jT5YpjtYHpVF2GEU6vhaf0K9L5o/6OIswBWJE2w2Opl9w4K/ib7F72We/QIFYg== 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 4Sr1jw66SZz15lB; Wed, 13 Dec 2023 16:52:20 +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 3BDGqK6U064836; Wed, 13 Dec 2023 16:52:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BDGqKHP064834; Wed, 13 Dec 2023 16:52:20 GMT (envelope-from git) Date: Wed, 13 Dec 2023 16:52:20 GMT Message-Id: <202312131652.3BDGqKHP064834@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: d04415c520b0 - main - loader: lua: remove the default kernel if it doesn't exist List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: d04415c520b031fb8eb93cb252e4acee66149c87 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d04415c520b031fb8eb93cb252e4acee66149c87 commit d04415c520b031fb8eb93cb252e4acee66149c87 Author: Kyle Evans AuthorDate: 2023-12-13 16:52:14 +0000 Commit: Kyle Evans CommitDate: 2023-12-13 16:52:14 +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 Differential Revision: https://reviews.freebsd.org/D42967 --- 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 c7581b296b8f..9226de564348 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -201,17 +201,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 @@ -239,6 +240,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. @@ -267,8 +270,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