freebsd-src icon indicating copy to clipboard operation
freebsd-src copied to clipboard

wordexp(3): Handle ECHILD from waitpid

Open kennylevinsen opened this issue 8 months ago • 2 comments

If the calling process has used SIG_IGN as handler or set the SA_NOCLDWAIT flag for SIGCHLD, processes will be automatically reaped on exit and calls to waitpid(3) will therefore fail with ECHILD.

We waitpid primarily to reap our child so that the caller does not have to worry about it. ECHILD indicates that there is no child to reap, so we can just treat that as a success and move on.

kennylevinsen avatar Apr 22 '25 09:04 kennylevinsen

Gentle ping

/cc @jbeich

kennylevinsen avatar May 30 '25 11:05 kennylevinsen

Thanks for the review!

It would be nice to add a variation of with_SIGCHILD_handler_test to lib/libc/tests/gen/wordexp_test.c to verify the fix works and keeps working.

Makes sense, did a simple copy-paste replacing the handler with SIG_IGN. As I had jbeich verify the original patch I never got around to spinning up a FreeBSD test environment, hopefully CI is good enough to check the test case.

(I considered adding another test for SA_NOCLDWAIT, but it should yield the exact same kernel behavior.)

kennylevinsen avatar May 30 '25 21:05 kennylevinsen

Merged as da9e73e5d483c47e67b3094356dd4b640749849e, thanks.

jillest avatar Jul 09 '25 21:07 jillest

@jillest, do you plan to MFC to stable/14? I'm trying to figure out how to phase out Sway workaround.

  • stable/13 reaches EOL on 2026-04-30. If Sway 1.12 is out before the workaround may need to be rebased. Alternatively, the port/package can be left partially broken near EOL.
  • stable/14 reaches EOL on 2028-11-30. Until then Sway may release 1.12, 1.13, 1.14, so rebasing the workaround may become tricky.
  • stable/15 is scheduled for 2025-09-05 (plus 2 months to release). No need for the workaround. Unfortunately, many users may delay upgrade from 14.* releases until 15.1 is out.

jbeich avatar Jul 15 '25 20:07 jbeich

@jillest, do you plan to MFC to stable/14?

Yes, to stable/14 and stable/13.

jillest avatar Jul 25 '25 13:07 jillest