From 9398a495eb305d5bf240bc998ee2f6128d75f4ca Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 26 Feb 2024 20:19:58 -0700 Subject: [PATCH] loader: Add loader.exit Add loader.exit(status). While one can get alomst this behavior with loader.perform("quit"), quit doesn't allow a value to be returned to the firmware. The interpretation of 'status' is firmware specific. This can be used when autobooting doesn't work in scripts, for example, to allow the firmware to try something else... Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D44094 --- stand/liblua/lutils.c | 16 ++++++++++++---- stand/lua/loader.lua.8 | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/stand/liblua/lutils.c b/stand/liblua/lutils.c index 0be9f5f28ac3..874dc8bf7d5d 100644 --- a/stand/liblua/lutils.c +++ b/stand/liblua/lutils.c @@ -109,6 +109,13 @@ lua_perform(lua_State *L) return 1; } +static int +lua_exit(lua_State *L) +{ + exit(luaL_checkinteger(L, 1)); + return 0; +} + static int lua_command_error(lua_State *L) { @@ -380,14 +387,15 @@ lua_writefile(lua_State *L) #define REG_SIMPLE(n) { #n, lua_ ## n } static const struct luaL_Reg loaderlib[] = { - REG_SIMPLE(delay), - REG_SIMPLE(command_error), REG_SIMPLE(command), - REG_SIMPLE(interpret), - REG_SIMPLE(parse), + REG_SIMPLE(command_error), + REG_SIMPLE(delay), + REG_SIMPLE(exit), REG_SIMPLE(getenv), REG_SIMPLE(has_command), REG_SIMPLE(has_feature), + REG_SIMPLE(interpret), + REG_SIMPLE(parse), REG_SIMPLE(perform), REG_SIMPLE(printc), /* Also registered as the global 'printc' */ REG_SIMPLE(setenv), diff --git a/stand/lua/loader.lua.8 b/stand/lua/loader.lua.8 index ff3b91ddfb09..e5aee7e8602d 100644 --- a/stand/lua/loader.lua.8 +++ b/stand/lua/loader.lua.8 @@ -61,6 +61,10 @@ Returns the error string from the last command to fail. Like .Fn perform but the arguments are already parsed onto the stack. +.It Fn exit status +Exit the boot loader back to the firmware with a status of +.Va status . +The interpretation of this value is firmware specific. .It Fn interpret str Execute the loader builtin command .Va str