[Concept,01/19] sandbox: Pass exit code through sandbox_exit()
Commit Message
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(-)
@@ -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 */
@@ -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
@@ -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);
}
}
@@ -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;
}