Improve error handling when determining parent process path
This commit is contained in:
parent
b2d14aff4d
commit
a4ea97016a
@ -247,6 +247,13 @@ then
|
|||||||
else
|
else
|
||||||
HOMEBREW_BREW_CALLER="$(readlink -f "/proc/${PPID}/exe")"
|
HOMEBREW_BREW_CALLER="$(readlink -f "/proc/${PPID}/exe")"
|
||||||
fi
|
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}" ]]
|
if [[ "${HOMEBREW_BREW_CALLER:-}" != "${HOMEBREW_FORCE_BREW_WRAPPER}" ]]
|
||||||
then
|
then
|
||||||
@ -269,7 +276,7 @@ or that ${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW} comes before ${HOMEBREW_PREF
|
|||||||
EOS
|
EOS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset HOMEBREW_BREW_CALLER
|
unset HOMEBREW_BREW_CALLER HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# commands that take a single or no arguments and need to write to HOMEBREW_PREFIX.
|
# commands that take a single or no arguments and need to write to HOMEBREW_PREFIX.
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
pid = ARGV[0]&.to_i
|
pid = ARGV[0]&.to_i
|
||||||
exit 1 unless pid
|
raise "Missing `pid` argument!" unless pid
|
||||||
|
|
||||||
require "fiddle"
|
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/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
|
# 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)
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user