tooldata_db: Fix signal handling - waiting for multiple processes#3833
Open
smoe wants to merge 1 commit intoLinuxCNC:2.9from
Open
tooldata_db: Fix signal handling - waiting for multiple processes#3833smoe wants to merge 1 commit intoLinuxCNC:2.9from
smoe wants to merge 1 commit intoLinuxCNC:2.9from
Conversation
In tooldata_db.cc (line 67), the old code does: 1. waitpid(..., WNOHANG) in a while (...) ; loop with an empty body. 2. Then evaluates WIFSIGNALED(status) and WIFEXITED(status) once, after the loop. The problem is: 1. waitpid only writes status when it returns > 0. 2. With WNOHANG, it can return 0 immediately (no state change yet), or -1 on error. 3. In those cases, status is not guaranteed to be written. 4. The code then reads status anyway via WIF* macros, so it can read stale/uninitialized data. 5. That can cause false logs and incorrectly set db_live = 0. What the patch changes: 1. It moves WIFSIGNALED/WIFEXITED checks inside the while (waitpid(...) > 0) loop. 2. status is only inspected in iterations where waitpid definitely produced a valid child status. 3. If no child was reapable, the loop does not run, and nothing is logged or toggled. 4. If multiple children changed state, each valid status is handled, instead of only the last one.
Collaborator
|
Is there a real problem? To me it looks like SIGCHLD cause signal handler to fire, the while loop eats all available signal info until the WNOHANG case causes waitpid to return 0. If waitpid indeed doesn't alter status in this case (man page is avoiding that topic), it should contain the status of the last signal returned by watipid (and there should be one because we are in a signal handler). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I need some help with this one. It is all a bit confusing. Am I confused?
In tooldata_db.cc (line 67), the old code does:
The problem is:
What the patch changes:
I patched this against 2.9. But if that is too risky then maybe 2.10 is preferable to give this some time to mature? But then again, we should somehow figure out if this change is correct or not. :-)