Skip to content
This repository

Lookup shell from running binary on systems with a /proc fs #1098

Closed
wants to merge 1 commit into from

3 participants

Richo Healey Jason Dunn Michal Papis
Richo Healey
Collaborator

Any reason not to do this?

Jason Dunn

I tested on Cygwin and it succeeds.

$ basename $(readlink -f /proc/$$/exe)
bash
Richo Healey
Collaborator

Awesome thanks @Dunnzilla

Michal Papis
Collaborator

we are interesting in the name that was used to start the shell, not the binary used

$ sh -
$ ps -p $$ -o comm=
sh
$ basename $(readlink -f /proc/$$/exe)
bash
Michal Papis
Collaborator

man bash:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.

Michal Papis
Collaborator

maybe we should write requirements for cygwin and just include ps on the list?

Richo Healey
Collaborator

There has to be a better way for all platforms. I'll have a think about it.

Michal Papis
Collaborator

@richo I've spent few days to get to the current code, could not find anything better, maybe you will have more luck ... but do not push to much, remember plans for RVM2 - maybe better to put our efforts there ...

Michal Papis
Collaborator

Maybe I missed to mention the most important bit of information, the sh shell is used by X server, this leads to loading rvm in unsupported environment and giving code errors on stderr - this leads to breaking server. This issue was observed on Fedora 16 or 17 and some Ubuntu or Debian. Also we use strictly bash / zsh compliant code in rvm and those loading from non bash/zsh shell should be not allowed.

In RVM2 all the code will be handled by internal (separate) shell binary, communication with other shells will be made via code evaluation - so only minimal efforts will be required to integrate as most of the code will be handled and tested using one shell.

Richo Healey
Collaborator

Closing until I've had a change to think about this a bit more.

Richo Healey richo closed this
Jason Dunn

FWIW, the problem is not that 'ps' is missing from Cygwin. The problem is 'ps' on Cygwin does not support the -o flag, on which rvm relies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 06, 2012
Richo Healey richo Lookup shell from running binary on systems with a /proc fs fa05ab5
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. +9 2 scripts/functions/installer
11 scripts/functions/installer
@@ -841,9 +841,16 @@ setup_etc_profile()
841 841 # /etc/profile.d/rvm.sh # sh extension required for loading.
842 842 #
843 843
  844 +
  845 +if test -d /proc
  846 +then
  847 + shell=\$(basename \$(readlink -f /proc/\$\$/exe))
  848 +else
  849 + shell=\"\`ps -p \$\$ -o comm=\`\"
  850 +fi
844 851 if [ -n \"\${BASH_VERSION:-}\" -o -n \"\${ZSH_VERSION:-}\" ] &&
845   - test \"\`ps -p \$\$ -o comm=\`\" != dash &&
846   - test \"\`ps -p \$\$ -o comm=\`\" != sh
  852 + test \"\$shell\" != dash &&
  853 + test \"\$shell\" != sh
847 854 then
848 855
849 856 : rvm_stored_umask:\${rvm_stored_umask:=\$(umask)}

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.