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
utils/fork: handle termsig in safe_fork #10686
Conversation
Review period will end on 2021-02-24 at 21:42:58 UTC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we didn't use Marshall
here, sorry 😭
Library/Homebrew/utils/fork.rb
Outdated
@@ -51,7 +53,7 @@ def self.safe_fork | |||
# to rescue them further down. | |||
if e.is_a?(ErrorDuringExecution) | |||
error_hash["cmd"] = e.cmd | |||
error_hash["status"] = e.status.exitstatus | |||
error_hash["status"] = Base64.encode64(Marshal.dump(e.status)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error_hash["status"] = Base64.encode64(Marshal.dump(e.status)) | |
error_hash["status"] = e.status&.exitstatus |
and instead never assume that this is non-nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough on Marshal, but the problem isn't status
being nil. It's exitstatus
being nil. If exitstatus
is nil, then we need to use termsig
(see ErrorDuringExecution
and its handling of a Process::Status
object). So will have to change around the API a bit (both exitstatus
and termsig
are integers and we need to differentiate between the two if we pass it here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing API around seems fine to me. As long as we assume non-zero status code I don't think preserving this is super critical (but I'll happily see a more comprehensive fix)
Review period ended. |
ceb3d46
to
c158e19
Compare
This way should be the cleanest/least disruptive. |
7b6c212
to
db8f9ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, nice work on this cleanup!
db8f9ce
to
f079373
Compare
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?When
safe_fork
fails due to application termination rather than exist,exitstatus
will be nil. Instead we should pass more of the object, as it has other methods liketermsig
for those cases. When you passErrorDuringExecution
aProcess::Status
object, it will handle that and provide proper information on the failure, rather than choking because the passed exit status is nil.It is unfortunately impossible to create a
Process::Status
object without usingMarshal.load
. There is no security risk though as this isn't user input.Fixes #10661.