selftests/cgroup: Decode waitid results correctly in clone_reap

clone_reap() applies the waitpid() status macros to waitid()'s
si_status. Unlike waitpid()'s encoded status, si_status already holds
the exit code or signal number, and si_code identifies the event.

For example, a child exiting with status 128 is reported as successful,
while a child exiting with status 42 produces -1 rather than 42. Stop
and continuation events are also rejected. With WNOHANG, a live child
can be reported as having exited successfully because the zeroed
si_status passes WIFEXITED().

Check si_code for the requested event and return si_status directly
for exit and stop events. Accept CLD_TRAPPED along with CLD_STOPPED,
as both correspond to stopped children.

Signed-off-by: Kanishk Singh <kanishk2607@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
1 file changed