mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] hush: fix last_return_code when PROMPT_COMMAND is used
Date: Wed, 17 Sep 2025 15:36:24 +0200	[thread overview]
Message-ID: <20250917133624.2993647-1-s.hauer@pengutronix.de> (raw)

Wenn PROMPT_COMMAND is used then a "echo $?" shows the result of the
PROMPT_COMMAND instead of the result of the last command. Fix this by
restoring the previous value after PROMPT_COMMAND has been executed.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/hush.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/hush.c b/common/hush.c
index 8515e77338..ec3c0cd913 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -433,9 +433,13 @@ static char *getprompt(void)
 
 	prompt_command = getenv("PROMPT_COMMAND");
 	if (prompt_command) {
+		unsigned int lr = last_return_code;
+
 		initialize_context(&ctx);
 		parse_string_outer(&ctx, prompt_command, FLAG_PARSE_SEMICOLON);
 		release_context(&ctx);
+
+		last_return_code = lr;
 	}
 
 	ps1 = getenv("PS1");
-- 
2.47.3




             reply	other threads:[~2025-09-17 13:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17 13:36 Sascha Hauer [this message]
2025-09-18 14:23 ` Sascha Hauer

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=20250917133624.2993647-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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