casaroli opened a new pull request, #3872: URL: https://github.com/apache/nuttx-apps/pull/3872
## Summary NSH kept only whether the last command failed: - `nsh_builtin()` and `nsh_fileapp()` returned 1 for any non-zero exit status. - `$?` expanded to 0 or 1. - `sh -c command` exited with the result of `nsh_parse()`: 0 or 255 (-1), never the exit status of the command. So `system()`, `popen()`/`pclose()` and any other caller of `sh -c` could not get the exit status of the command. This PR keeps the exit status of the last command in `np_status`. `nsh_builtin()` and `nsh_fileapp()` return the exit status of the application, `$?` expands to it, and `sh -c` exits with it, as POSIX requires. A command line that cannot be run still gives `EXIT_FAILURE`. The two TODO comments about `$?` are done. The first commit only fixes the old nxstyle errors in `nsh_builtin.c` and `nsh_fileapps.c`. ## Impact `$?` and the exit status of `sh -c` are the exit status of the command, not 0/1 or 0/255. The conditions of `if`, `while` and `until` work as before. apache/nuttx#NNNN updates the description of `$?` in the NSH documentation. ## Testing `qemu-armv8a:knsh` (QEMU 11 with HVF on an Apple M4), file apps: a test program runs `sh -c` with these commands: | `sh -c` command | master | this PR | |---|---|---| | `shstatus --exit 3` | 255 | 3 | | `shstatus --exit 0` | 0 | 0 | | `no_such_command` | 255 | 1 | | `shstatus --exit 5; shstatus --exit $?` | 255 | 5 | `qemu-armv8a:nsh` (QEMU, TCG), built-in apps: `set +e; popen_test --exit 3; echo st=$?` prints `st=1` on master and `st=3` with this PR (`popen_test --exit` from apache/nuttx-apps#3871). `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` ends with `ostest_main: Exiting with status 0`. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
