8000 wordexp(3): Handle ECHILD from waitpid by kennylevinsen · Pull Request #1675 · freebsd/freebsd-src · GitHub
[go: up one dir, main page]

Skip to content

wordexp(3): Handle ECHILD from waitpid #1675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kennylevinsen
Copy link

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
Copy link
Author

Gentle ping

/cc @jbeich

Copy link
Member
@jillest jillest left a comment

Choose a reason for hiding this comment

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

The exit status is indeed unnecessary to detect errors since the output is sufficiently clear.

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.

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.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
@kennylevinsen
Copy link
Author

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0