[Concept,01/19] sandbox: Pass exit code through sandbox_exit()

Message ID 20260314231618.338113-2-sjg@u-boot.org
State New
Headers
Series test: Fix pytest inter-test side effects |

Commit Message

Simon Glass March 14, 2026, 11:15 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

sandbox_exit() always exits with code 0, discarding any error from
the caller. The -c command path worked around this by calling
os_exit() directly, bypassing state_uninit() and losing cleanup
such as writing the malloc dump.

Add an exit_code parameter to sandbox_exit() so callers can propagate
errors while still getting a clean shutdown. Update all callers to
pass 0 except sandbox_main_loop_init() which passes the command
return value.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/cpu.c                    | 5 ++---
 arch/sandbox/include/asm/u-boot-sandbox.h | 2 +-
 arch/sandbox/lib/interrupts.c             | 2 +-
 drivers/sysreset/sysreset_sandbox.c       | 4 ++--
 4 files changed, 6 insertions(+), 7 deletions(-)
  

Patch

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index d6177fbbd14..791af49464b 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -20,7 +20,7 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-void __noreturn sandbox_exit(void)
+void __noreturn sandbox_exit(int exit_code)
 {
 	/* Do this here while it still has an effect */
 	os_fd_restore();
@@ -28,8 +28,7 @@  void __noreturn sandbox_exit(void)
 	if (state_uninit())
 		os_exit(2);
 
-	/* This is considered normal termination for now */
-	os_exit(0);
+	os_exit(exit_code);
 }
 
 /* delay x useconds */
diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h
index 941f35f9e69..60fb300f623 100644
--- a/arch/sandbox/include/asm/u-boot-sandbox.h
+++ b/arch/sandbox/include/asm/u-boot-sandbox.h
@@ -41,7 +41,7 @@  struct udevice;
 void sandbox_reset(void);
 
 /* Exit sandbox (quit U-Boot) */
-void __noreturn sandbox_exit(void);
+void __noreturn sandbox_exit(int exit_code);
 
 /**
  * sandbox_init() - init sandbox
diff --git a/arch/sandbox/lib/interrupts.c b/arch/sandbox/lib/interrupts.c
index 3f6583e11f0..e9207b82032 100644
--- a/arch/sandbox/lib/interrupts.c
+++ b/arch/sandbox/lib/interrupts.c
@@ -53,6 +53,6 @@  void os_signal_action(int sig, unsigned long pc)
 		printf("resetting ...\n\n");
 		sandbox_reset();
 	} else {
-		sandbox_exit();
+		sandbox_exit(0);
 	}
 }
diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
index d126fad0372..6739ecbd92f 100644
--- a/drivers/sysreset/sysreset_sandbox.c
+++ b/drivers/sysreset/sysreset_sandbox.c
@@ -63,13 +63,13 @@  static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
 		state->last_sysreset = type;
 		if (!state->sysreset_allowed[type])
 			return -EACCES;
-		sandbox_exit();
+		sandbox_exit(0);
 	case SYSRESET_POWER:
 	case SYSRESET_HOT:
 	case SYSRESET_TO_FIRMWARE_UI:
 		if (!state->sysreset_allowed[type])
 			return -EACCES;
-		sandbox_exit();
+		sandbox_exit(0);
 	default:
 		return -EPROTONOSUPPORT;
 	}