[1.1] libct: fix a race with systemd removal #3877
Merged
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.
This is a backport of #3812 to release-1.1 branch. Original description follows.
For a previous attempt to fix that (and added test cases), see commit 9087f2e.
Alas, it's not always working because of cgroup directory TOCTOU.
To solve this and avoid the race, add an error after the operation. Implement it as a method that ignores the error that should be ignored. Instead of currentStatus(), use faster runType(), since we are not interested in Paused status here.
For Processes(), remove the pre-op check, and only use it after getting an error, making the non-error path more straightforward.
For Signal(), add a second check after getting an error. The first check is left as is because signalAllProcesses might print a warning if the cgroup does not exist, and we'd like to avoid that.
This should fix an occasional failure like this one:
(cherry picked from commit fe278b9)