git: 48b05b8fc248 - main - loader: set boot_safe when safe mode is selected

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 14 Dec 2024 04:31:58 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=48b05b8fc2485ba5cc7ba7b52c62965feea101a8

commit 48b05b8fc2485ba5cc7ba7b52c62965feea101a8
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-12-14 04:31:22 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-12-14 04:31:28 +0000

    loader: set boot_safe when safe mode is selected
    
    This may be used to disable or limit functionality of some services
    when safe mode is selected. The particular value of boot_safe should not
    be considered significant, only its presence in the environment.
    
    Reviewed by:    imp, tsoome
    Differential Revision:  https://reviews.freebsd.org/D32172
---
 stand/forth/menu-commands.4th |  2 ++
 stand/lua/core.lua            |  2 ++
 stand/man/loader_simp.8       | 17 ++++++++++++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/stand/forth/menu-commands.4th b/stand/forth/menu-commands.4th
index 2c3d787c65e1..13bbcf73201c 100644
--- a/stand/forth/menu-commands.4th
+++ b/stand/forth/menu-commands.4th
@@ -128,6 +128,7 @@ also menu-namespace also menu-command-helpers
 	s" set hw.ata.atapi_dma=0" evaluate
 	s" set kern.eventtimer.periodic=1" evaluate
 	s" set kern.geom.part.check_integrity=0" evaluate
+	s" set boot_safe=YES" evaluate
 ;
 
 : safemode_disable ( -- )
@@ -136,6 +137,7 @@ also menu-namespace also menu-command-helpers
 	s" hw.ata.atapi_dma" unsetenv
 	s" kern.eventtimer.periodic" unsetenv
 	s" kern.geom.part.check_integrity" unsetenv
+	s" boot_safe" unsetenv
 ;
 
 : init_safemode ( N -- N )
diff --git a/stand/lua/core.lua b/stand/lua/core.lua
index 3582720f2a81..5976cc65156d 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -179,12 +179,14 @@ function core.setSafeMode(safe_mode)
 		loader.setenv("hw.ata.atapi_dma", "0")
 		loader.setenv("kern.eventtimer.periodic", "1")
 		loader.setenv("kern.geom.part.check_integrity", "0")
+		loader.setenv("boot_safe", "YES")
 	else
 		loader.unsetenv("kern.smp.disabled")
 		loader.unsetenv("hw.ata.ata_dma")
 		loader.unsetenv("hw.ata.atapi_dma")
 		loader.unsetenv("kern.eventtimer.periodic")
 		loader.unsetenv("kern.geom.part.check_integrity")
+		loader.unsetenv("boot_safe")
 	end
 	core.sm = safe_mode
 end
diff --git a/stand/man/loader_simp.8 b/stand/man/loader_simp.8
index 49214e78b494..cdacd823b1a5 100644
--- a/stand/man/loader_simp.8
+++ b/stand/man/loader_simp.8
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd September 29, 2021
+.Dd September 30, 2021
 .Dt LOADER_SIMP 8
 .Os
 .Sh NAME
@@ -339,6 +339,21 @@ In a running system, the state of console muting can be manipulated by the
 utility.
 .It Va boot_pause
 During the device probe, pause after each line is printed.
+.It Va boot_safe
+Force userland to boot in
+.Dq safe mode ,
+which may disable or limit the functionality of some services that may not be
+desired in safe mode.
+This is typically set by selecting
+.Dq safe mode
+in the loader menu, which also sets some other hints for the kernel.
+Applications wishing to respect safe mode should
+.Sy only
+test for the presence of
+.Va boot_safe
+in
+.Xr kenv 1 ,
+not for any particular value.
 .It Va boot_serial
 Force the use of a serial console even when an internal console
 is present.