Repository navigation
nshlib: Restore the console after a redirected "source". - #3915
Merged
xiaoxiang781216 merged 1 commit intoOct 26, 2026
Merged
Conversation
nsh_execute() redirects the output of an NSH command, runs it, and then restores the output if one of the np_redir_* flags is set. "source" and "." parse each line of the script with the same vtbl, and nsh_parse_command() clears these flags for each line. After a script with a redirection, for example "source script > /dev/null", NSH did not call nsh_undirect(): the console kept the closed redirection file descriptor as its output, so the prompt and all later output were lost and NSH looked hung. Keep the redirection state in a local variable and restore the output when it is set. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Oct 25, 2026
Contributor
|
ci break fixed by #3914 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nsh_execute()redirects the output of an NSH command, runs it, and then restores the output if one of thenp_redir_*flags is set.sourceand.parse each line of the script with the same vtbl, andnsh_parse_command()clears these flags for each line. So aftersource script > /dev/nullNSH did not callnsh_undirect(). The console kept the closed redirection descriptor as its output: the prompt and all later output were lost, and NSH looked hung.This PR keeps the redirection state in a local variable and restores the output when it is set.
Impact
Only NSH commands that parse more lines with the same vtbl (
source,.) and have a redirection. Other commands do not change.Testing
qemu-armv8a:knsh under QEMU with HVF, NSH from this branch, a script
e4.shwith one lineecho E4-INNER:source e4.shsource e4.sh > /dev/null, thenecho E4-AFTER1source e4.sh > e4.out, thencat e4.out. e4.sh 2> /dev/null, thenecho E4-AFTER2ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh (NSH from this branch).
Build with NuttX master, each OK: qemu-armv8a:nsh (flat, arm64), qemu-armv8a:knsh (kernel, arm64), rv-virt:nsh64 (flat, rv64), rv-virt:pnsh64 (protected, rv64).
tools/checkpatch.sh -c -u -m -gpasses. No documentation change.