Skip to content
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

fix(dist/linux): handle the possible unavailability of /proc in rustup-init.sh #3800

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rami3l
Copy link
Member

@rami3l rami3l commented May 1, 2024

Closes #2700. I'm no shell expert, just trying to do my best...

This fix is based on @miigotu and @kerberjg's find in #2700 (comment) and #2700 (comment) respectively. It first refers to /proc/self/exe if it's accessible, then $SHELL if it's set, and finally /bin/sh. This executable is then explicitly passed to functions that previously relied on /proc/self/exe.

有備無患 yǒu bèi wú huàn

  • to be prepared against adverse events

Concerns

  • What about the grep '^Features' /proc/cpuinfo line which also relies on /proc? Fixed.
  • How to test this patch?
    • The podman instance I use seems to have /proc access. I've tested the patch with a modified /proc path (/fakeproc) and the logic seems to work.

@rami3l rami3l added this to the 1.28.0 milestone May 1, 2024
@rami3l rami3l changed the title fix(dist): add fallbacks to /proc/self/exe in rustup-init.sh fix(dist): handle the possible unavailability of /proc in rustup-init.sh May 1, 2024
@rami3l rami3l changed the title fix(dist): handle the possible unavailability of /proc in rustup-init.sh fix(dist/linux): handle the possible unavailability of /proc in rustup-init.sh May 1, 2024
@rami3l rami3l requested a review from djc May 1, 2024 07:19
@rami3l rami3l marked this pull request as ready for review May 1, 2024 07:19
@rami3l rami3l requested a review from rbtcollins May 7, 2024 07:15
case "$_ostype" in

Android)
_ostype=linux-android
;;

Linux)
check_proc
get_current_exe
_current_exe=$RETVAL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use

_current_exe=get_current_exe

Copy link
Member Author

@rami3l rami3l May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbtcollins I assume you meant _current_exe=$(get_current_exe)?

The echo "Warning: ..." calls in the function body will interfere with the function's output when it's being used like so (unless the 1>&2 trick is used, as I understand it). Looking at the surrounding code, it seems like the $RETVAL trick is used exactly in this case to specify the actual value to be returned.

I referred to downloader() as an example when writing this. This is how it calls other functions via $RETVAL:

rustup/rustup-init.sh

Lines 596 to 599 in 2a5a69e

check_curl_for_retry_support
_retry="$RETVAL"
get_ciphersuites_for_curl
_ciphersuites="$RETVAL"

This is how it issues warnings:

echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure"

Maybe we should use 1>&2 for echo commands instead? But in that case we might hit #3350, right?

@rbtcollins
Copy link
Contributor

I think this looks reasonable.

There are other probes we could use, such as uname and lsb_release and gcc but they all have edge cases and caveats. One question for you then GTG IMO.

if test -L /proc/self/exe ; then
_current_exe=/proc/self/exe
else
echo "Warning: Unable to find /proc/self/exe. System architecture detection might be inaccurate."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, a tiny typo here...

Suggested change
echo "Warning: Unable to find /proc/self/exe. System architecture detection might be inaccurate."
echo "Warning: Unable to find /proc/self/exe. System architecture detection might be inaccurate."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustup-init.sh fails to detect platform correctly under docker buildx which lacks /proc
2 participants