cederom commented on PR #22583:
URL: https://github.com/apache/nuttx/pull/22583#issuecomment-7296800481
Thanks. The two macros match BSD/glibc, and `W_EXITCODE(r, 0)` /
`W_STOPCODE(s)` give exactly what `nxsched_waitpid()` stores today (`si_status
<< 8` and `WAIT_STOPPED()`). A few comments:
**1. `W_EXITCODE(0, sig)` makes a status that this header can't decode**
The commit message says the macros are for programs that report the status
of a child they ended themselves. That is usually `W_EXITCODE(0, SIGKILL)` or
`W_EXITCODE(0, SIGTERM)`. With the decoders in this header:
W_EXITCODE(0, SIGKILL) = 0x9
WIFEXITED = 0, WIFSIGNALED = 0, WIFSTOPPED = 0, WIFCONTINUED = 0,
WTERMSIG = 0
So the value matches none of the cases. The reason is that `WTERMSIG()` and
`WCOREDUMP()` read bits 8..15 (`(s) >> 8`), but the BSD/glibc layout used by
`W_EXITCODE()` puts the termination signal in bits 0..6 and the core flag in
bit 7. On BSD and glibc: `WTERMSIG(s) = (s) & 0x7f`, `WCOREDUMP(s) = (s) &
0x80`, `WIFSIGNALED(s) = ((s) & 0x7f) != 0 && ((s) & 0x7f) != 0x7f`.
Could this PR also switch those three macros to the BSD definitions? It
looks safe. The BSD `WIFSIGNALED()` is 0 for every status NuttX produces today
(exit `r << 8`, including negative `r`; stop `0x..7f`; continued `0xffff`), so
nothing that decodes real `waitpid()` results changes. After that,
`W_EXITCODE(0, sig)` round-trips. If you'd rather keep that separate, please at
least say in the header comment and in the docs that only `s == 0` is supported
for now.
**2. One definition instead of two**
`sched/sched/sched.h` already has `WAIT_STOPPED(signo)` (`(((signo) & 0xff)
<< 8) | 0x7f`), and `sched_waitpid.c` / `task_exithook.c` use a bare `status <<
8`. It would be nice to have the kernel use `W_STOPCODE()` /
`W_EXITCODE(status, 0)` and drop `WAIT_STOPPED()`, so the encoding lives in one
place. That could be a follow-up.
**3. Wording**
"(not POSIX, as on other systems)" can be read two ways. Suggest: "These are
not POSIX; they are defined as in BSD and glibc." The same applies to the
header comment.
Nit, pre-existing: the encoding comment above says "2 bytes of _info then
two bytes of code", but it is one byte of each (`0xffff` being the exception).
Since you're touching this block, you could fix that too.
--
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]