Skip to content

games/NXDoom, testing/ostest: Check WIFEXITED() before WEXITSTATUS(). - #3905

Merged
xiaoxiang781216 merged 4 commits into
apache:masterfrom
casaroli:wexitstatus-check
Oct 24, 2026
Merged

xiaoxiang781216 merged 4 commits into
apache:masterfrom
casaroli:wexitstatus-check

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

Summary

POSIX defines WEXITSTATUS() only when WIFEXITED() is true (wait()): "If the value of WIFEXITED(stat_val) is non-zero, this macro shall evaluate to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main()." For a child that a signal ended, the value of WEXITSTATUS() is not an exit code, and it can be 0.

Two places in nuttx-apps used WEXITSTATUS() without WIFEXITED():

  • games/NXDoom/textscreen/txt_fileselect.c: the file selector took the output of its child as the result when WEXITSTATUS() was 0. It now takes it only if the child exited and its exit status is 0.
  • testing/ostest/waitpid.c: three checks compared WEXITSTATUS() with the expected exit code. They now check WIFEXITED() first, and an error prints the whole status.

The other users in nuttx-apps already check WIFEXITED() first.

Two small commits come first, so that the style check passes on the whole files: two older nxstyle errors in txt_fileselect.c (a blank line, braces for an empty for loop), and a spelling error in a message of waitpid.c.

Impact

None for a child that exits normally. A child that a signal ends is no longer taken as a success by the NXDoom file selector or by the ostest waitpid checks.

Testing

ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh (QEMU with HVF), with this PR. On qemu-armv8a:nsh (with CONFIG_SCHED_WAITPID and CONFIG_SCHED_CHILD_STATUS) the three changed waitpid checks run and pass (stat_loc=0e00, exit status 14). raspberrypi-4b:nxdoom (arm64) builds with this PR, so txt_fileselect.c compiles.

tools/checkpatch.sh -c -u -m -g passes.

Add a blank line after a declaration, and give an empty for loop
braces, so that the next commit passes the style check.  No functional
change.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
The file selector takes the output of its child as the result only if
WEXITSTATUS() of the child is 0.  POSIX defines WEXITSTATUS() only when
WIFEXITED() is true: for a child that a signal ended, the value is not
an exit code, and it can be 0.

Take the result only if the child exited and its exit status is 0.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
"exitting" is "exiting" in a printed message.  No other change.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
The waitpid tests compared WEXITSTATUS() of each child with the
expected exit code, without WIFEXITED().  POSIX defines WEXITSTATUS()
only when WIFEXITED() is true, so a child that a signal ended would not
be seen as an error if the value matched.

Check WIFEXITED() first, and print the whole status on an error.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli :-)

Please squash two commits of a single file - first with code change and second with formatting to a single commit - why split into two commits?

@xiaoxiang781216
xiaoxiang781216 merged commit 496535e into apache:master Oct 24, 2026
69 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants