git: e6bc3b2da9a4 - main - lualoader: don't run a failed command twice from the prompt

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Thu, 26 Nov 2026 04:02:35 UTC
The branch main has been updated by kevans:

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

commit e6bc3b2da9a4bc5af5aaa3ebfe26d26fb9d11b08
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-11-26 04:00:54 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-11-26 04:01:03 +0000

    lualoader: don't run a failed command twice from the prompt
    
    interp_run() hands each command line to cli_execute, which runs
    builtins through loader.command.  If that returned an error, it then
    ran the command again with interp_builtin_cmd(), as a fallback for when
    lua couldn't run the command at all.  A command that simply failed thus
    ran twice, printing any errors twice and repeating whatever it did
    before it failed.
    
    Only fall back when the lua call itself failed, and otherwise take the
    command's own result.
    
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D61845
---
 stand/common/interp_lua.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/stand/common/interp_lua.c b/stand/common/interp_lua.c
index 2a61bb9d04af..b7e0a18cf56d 100644
--- a/stand/common/interp_lua.c
+++ b/stand/common/interp_lua.c
@@ -188,7 +188,7 @@ interp_run(const char *line)
 			status = lua_pcall(luap, argc, 1, 0);
 			ret = lua_tointeger(luap, 1);
 			lua_pop(luap, 1);
-			if (status != 0 || ret != 0) {
+			if (status != 0) {
 				/*
 				 * Lua cli_execute will pass the function back
 				 * through loader.command, which is a proxy to
@@ -198,6 +198,15 @@ interp_run(const char *line)
 				 * directly if our lua_pcall was not successful.
 				 */
 				status = interp_builtin_cmd(argc, argv);
+			} else {
+				/*
+				 * cli_execute() is responsible for sending any
+				 * command that it doesn't want to handle back
+				 * through the C bits via loader.perform(), so
+				 * as long as the lua_pcall succceeded we will
+				 * trust the result.
+				 */
+				status = ret;
 			}
 			if (status != 0) {
 				if (command_errmsg != NULL)