Permalink
Browse files

Work around a couple of corner cases that cause failure and/or fork b…

…ombs.
  • Loading branch information...
directionless committed Sep 26, 2011
1 parent 892ceaa commit 207f003697f9439f119a57245fcea305a5fcb48a
Showing with 24 additions and 9 deletions.
  1. +24 −9 binscripts/rvm
View
@@ -21,17 +21,32 @@ then
done
fi
-if [[ -z "${rvm_path:-""}" ]]
-then
- if (( UID == 0 ))
- then
+# This logic is to help detect where rvm is being run from. It's needs
+# to detect user vs system, and mostly survive through various
+# privledge escalation tools (sudo, su, etc)
+#
+# The case to avoid, is trying to source a file that doesn't exist,
+# and causing a fork bomb.
+#
+# if rvm_path is set, use that
+# elsif ${HOME}/.rvm, use that
+# elsif /usr/local/rvm, use that
+# else, fail.
+#
+# And for extra checking, if we can't source what we need, don't re-exec.
+
+if [[ ! -z "${rvm_path:-""}" ]]; then
+ true
+elif (( UID == 0 )); then
rvm_path="/usr/local/rvm"
- else
+elif [[ -d "${HOME}/.rvm" ]]; then
rvm_path="${HOME}/.rvm"
- fi
+elif [[ -d "/usr/local/rvm" ]]; then
+ rvm_path="/usr/local/rvm"
+else
+ echo "Can't find rvm install" 1>&2
+ exit 1
fi
export rvm_path
-source "${rvm_scripts_path:="$rvm_path/scripts"}/rvm"
-
-rvm "$@"
+source "${rvm_scripts_path:="$rvm_path/scripts"}/rvm" && rvm "$@"

0 comments on commit 207f003

Please sign in to comment.