Reject wait4 options that Linux refuses

XA
15h ago
+68-2

Intent: Make wait4 refuse the options that Linux refuses.

Failure fixed: wait4(pid, NULL, WEXITED) reaps the child on elfuse. Linux 6.18 returns EINVAL and leaves the child, because only waitid takes WEXITED. box64 makes this call after a vfork, so dash under box64 got ECHILD from its own wait and reported 255 as the status of each command.

This PR: sys_wait4 checks the option bits before it looks for a child, as kernel_wait4 does.

  • With the fix, elfuse and Linux 6.18 (QEMU) agree on all 32 single option bits with no child, on every bit but __WCLONE with an exited child, and on each valid bit paired with each unknown one.
  • test-process-lifecycle WAIT-07 passes as is (3/3), fails with the fix reverted (3/3), and passes on Linux.
  • dash under box64 0.4.3, child exits 5: status 255 before, 5 after.
  • make check passes. make test-matrix: elfuse-aarch64 338 passed, 0 failed; qemu-aarch64 312 passed, 0 failed. audit-known-limitations fails in the Rosetta lane, and on d3c0785 too.

Left out: __WCLONE reaps an exited fork child where Linux returns ECHILD, waitid accepts unknown options and none, and wait4(INT_MIN) returns ECHILD where Linux returns ESRCH.

Refs #246


Summary by cubic

Rejects wait4 option bits that Linux refuses, so calls like wait4(pid, NULL, WEXITED) now return EINVAL on elfuse and leave the child instead of reaping it. Previously sys_wait4 ignored unknown options and consumed the child, which made shells under box64 see ECHILD from their own wait and report status 255 for every command.

  • Adds WAIT-07 to test-process-lifecycle, verifying all 32 option bits match Linux behavior.
  • Known gaps left out: waitid has the same gap for unknown options, and wait4(INT_MIN) returns ECHILD where Linux returns ESRCH.