Resolve symlinked java command to find home#6639
Merged
headius merged 8 commits intojruby:jruby-9.2from Mar 30, 2021
Merged
Conversation
On many Linux systems, the installed `java` command will live in /usr/bin and point via a chain of symlinks to the actual JDK home installation under (for example) /usr/lib/jvm/<java-home>. This symlinking interferes with our detecting where Java actually lives, leading to issues like jruby#6637. This patch uses existing logic for resolving a trail of symlinks, allowing us to dig down to the actual binary `java` and from there determine its JAVA_HOME. Fixes jruby#6637. See also jruby/jruby-launcher#34 which will need a similar fix in C.
These should be visible from within the launched JRuby process.
Member
Author
|
First attempt at a test failed, indicating that the JDK installs on Ubuntu also symlink |
There is no standard way in POSIX shell to determine the target of a symlink, so we are forced to use readlink.
export will hide the failure of the command on the RHS used as the value, so export only the variable names.
Member
Author
|
Additional improvements thanks to @mrnoname1000:
|
Member
Author
|
From de400b6:
|
headius
added a commit
that referenced
this pull request
Mar 31, 2021
I decided I am not comfortable with this change, since it would mean launching a subprocess JRuby with a different home or Java would require *clearing* these variables rather than just pointing at a new jruby or java executable. See #6639.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR fixes #6637 by fully resolving any symlinks between the
javacommand (found from$JAVACMDorjavain PATH) before using that command's path to determine$JAVA_HOME.The issue affects systems without
$JAVA_HOMEset, but that have ajavacommand in PATH that resolves to a$JAVA_HOME/bin/javathrough a series of symlinks (e.g. CentOS).This PR also exports
JRUBY_HOME,JAVACMD, andJAVA_HOMEso they will be seen by the JRuby process and subprocesses, avoiding recalculating this home or accidentally using a different JDK for additional JRuby launches.I have added a test case for the symlink situation.