Improve error handling when determining parent process path

This commit is contained in:
Carlo Cabrera 2025-08-13 17:54:29 +08:00 committed by Carlo Cabrera
parent b2d14aff4d
commit a4ea97016a
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 14 additions and 3 deletions

View File

@ -247,6 +247,13 @@ then
else
HOMEBREW_BREW_CALLER="$(readlink -f "/proc/${PPID}/exe")"
fi
HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE="$?"
if [[ "${HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE}" -ne 0 ]]
then
# Error message already printed above when populating `HOMEBREW_BREW_CALLER`.
odie "failed to check the path to the parent process!"
fi
if [[ "${HOMEBREW_BREW_CALLER:-}" != "${HOMEBREW_FORCE_BREW_WRAPPER}" ]]
then
@ -269,7 +276,7 @@ or that ${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW} comes before ${HOMEBREW_PREF
EOS
fi
unset HOMEBREW_BREW_CALLER
unset HOMEBREW_BREW_CALLER HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE
fi
# commands that take a single or no arguments and need to write to HOMEBREW_PREFIX.

View File

@ -3,7 +3,7 @@
# frozen_string_literal: true
pid = ARGV[0]&.to_i
exit 1 unless pid
raise "Missing `pid` argument!" unless pid
require "fiddle"
@ -29,4 +29,8 @@ pointer_to_buffer = Fiddle::Pointer.to_ptr(buffer)
# https://github.com/chromium/chromium/blob/86df41504a235f9369f6f53887da12a718a19db4/base/process/process_handle_mac.cc#L37-L44
# https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/libsyscall/wrappers/libproc/libproc.c#L263-L283
return_value = libproc_proc_pidpath_function.call(pid, pointer_to_buffer, buffer_size)
puts pointer_to_buffer.to_s.strip if return_value.positive?
if return_value.positive?
puts pointer_to_buffer.to_s.strip
else
raise "Call to `proc_pidpath` failed! `proc_pidpath` returned #{return_value}."
end