From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/5] boot: report the exit status of failing boot scripts
Date: Thu, 12 Nov 2026 09:50:13 +0100 [thread overview]
Message-ID: <9f650ecc-b0d6-4e79-98f7-5bdcfe96899c@pengutronix.de> (raw)
In-Reply-To: <20261030-devboot-v1-1-ab9dd3a92c66@pengutronix.de>
On 10/30/26 15:13, Sascha Hauer wrote:
> When a boot script exits with a non-zero status, execute_binfmt()
> returns that status as a positive value. bootscript_boot() passes it to
> strerror(-ret) and boot_entry() to %pe, both of which expect a negative
> errno, resulting in messages like:
>
> ERROR: Running script '/env/boot/mmc' failed: error -1
> ERROR: Booting entry 'mmc' failed: 0000000000000001
>
> Allow boot entries to return a boot script's exit status and have
> boot_entry() report it as such. bootscript_boot() now only reports
> errors of its own, so a failing script results in a single
>
> ERROR: Booting entry 'mmc' failed: exit status 1
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> common/boot.c | 11 +++++++----
> include/boot.h | 1 +
> test/py/test_boot_script.py | 13 +++++++++++++
> 3 files changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/common/boot.c b/common/boot.c
> index 023eaf5145..b993cabf65 100644
> --- a/common/boot.c
> +++ b/common/boot.c
> @@ -115,10 +115,11 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
> * without the shell expanding or splitting it first.
> */
> ret = execute_binfmt(bs->args ? 2 : 1, argv);
> - if (ret) {
> - pr_err("Running script '%s' failed: %s\n", bs->entry.path, strerror(-ret));
> + if (ret < 0)
> + pr_err("Running script '%s' failed: %pe\n", bs->entry.path, ERR_PTR(ret));
> + /* positive values are the exit status, reported by boot_entry() */
> + if (ret)
> return ret;
> - }
>
> /* No point in repeating bootm if script already called it */
> if (bootm_nattempts != bootm_command_attempts())
> @@ -206,7 +207,9 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
> scope = boot_globalvar_scope_push();
>
> ret = be->boot(be, verbose, dryrun);
> - if (ret && ret != -ENOMEDIUM)
> + if (ret > 0)
> + pr_err("Booting entry '%s' failed: exit status %d\n", be->title, ret);
> + else if (ret && ret != -ENOMEDIUM)
> pr_err("Booting entry '%s' failed: %pe\n", be->title, ERR_PTR(ret));
>
> globalvar_scope_pop(scope);
> diff --git a/include/boot.h b/include/boot.h
> index b30cdd314a..bb99dacc85 100644
> --- a/include/boot.h
> +++ b/include/boot.h
> @@ -20,6 +20,7 @@ struct bootentry {
> const char *title;
> char *description;
> const char *path;
> + /* 0 on success, else negative errno or a boot script's exit status */
> int (*boot)(struct bootentry *entry, int verbose, int dryrun);
> void (*release)(struct bootentry *entry);
> struct bootm_overrides overrides;
> diff --git a/test/py/test_boot_script.py b/test/py/test_boot_script.py
> new file mode 100644
> index 0000000000..be08e964d9
> --- /dev/null
> +++ b/test/py/test_boot_script.py
> @@ -0,0 +1,13 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +
> +def test_boot_script_exit_status(barebox):
> + barebox.run_check("echo -o /env/boot/exit3 '#!/bin/sh'")
> + barebox.run_check("echo -a /env/boot/exit3 'exit 3'")
> +
> + stdout, _, ret = barebox.run("boot exit3")
> + assert ret != 0
> + assert "ERROR: Booting entry 'exit3' failed: exit status 3" in stdout
> + assert not any("Running script" in line for line in stdout)
> +
> + barebox.run_check("rm /env/boot/exit3")
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-11-12 8:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 14:13 [PATCH 0/5] boot: implement devboot in C Sascha Hauer
2026-10-30 14:13 ` [PATCH 1/5] boot: report the exit status of failing boot scripts Sascha Hauer
2026-11-12 8:50 ` Ahmad Fatoum [this message]
2026-10-30 14:13 ` [PATCH 2/5] hush: export source_script() Sascha Hauer
2026-11-12 8:47 ` Ahmad Fatoum
2026-10-30 14:13 ` [PATCH 3/5] boot: hand overrides on to nested boots and the bootm command Sascha Hauer
2026-11-13 8:52 ` Ahmad Fatoum
2026-10-30 14:13 ` [PATCH 4/5] boot: implement devboot in C Sascha Hauer
2026-11-13 7:51 ` Ahmad Fatoum
2026-11-13 9:48 ` Sascha Hauer
2026-10-30 14:13 ` [PATCH 5/5] sandbox: defconfig: enable boot overrides and devboot Sascha Hauer
2026-11-12 8:48 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f650ecc-b0d6-4e79-98f7-5bdcfe96899c@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox