ysbaddaden / prax

Rack proxy server for development
http://ysbaddaden.github.io/prax/
Other
475 stars 49 forks source link

Hard reset of environment variables VS ruby version managers #73

Open ysbaddaden opened 10 years ago

ysbaddaden commented 10 years ago

I'm hard resetting the environment variables to almost nothing, in order for ruby version managers to not be influenced by the ruby version Prax is currently running with.

The problem is that the reset is so hard that not even HOME, USER and UID are kept.

I'm wondering how to correctly fix that problem: have a whitelist of environment variables that must be kept? Keep a hash of the original environment variables? Something else?

suan commented 10 years ago

How about purging all vars with RUBY, GEM, BUNDLE in it and PATH, and leave the rest as is?

ysbaddaden commented 10 years ago

Version managers are each setting their own vars, so it doesn't work to just clean some vars. Prax would have to know about all version managers and filter-out their variables —assuming they won't add more or change any.

mpapis commented 9 years ago

the important variables are set by the version managers, they are important for ruby not the manager, just make sure that the shell you use does not load any manager and resetting this variables should be enough:

GEM_HOME
GEM_PATH

+ all listed here http://www.tutorialspoint.com/ruby/ruby_environment_variables.htm:

DLN_LIBRARY_PATH    # Search path for dynamically loaded modules.
HOME        # Directory moved to when no argument is passed to Dir::chdir. Also used by File::expand_path to expand "~".
LOGDIR      # Directory moved to when no arguments are passed to Dir::chdir and environment variable HOME isn't set.
PATH        # Search path for executing subprocesses and searching for Ruby programs with the -S option. Separate each path with a colon (semicolon in DOS and Windows).
RUBYLIB     # Search path for libraries. Separate each path with a colon (semicolon in DOS and Windows).
RUBYLIB_PREFIX  # Used to modify the RUBYLIB search path by replacing prefix of library path1 with path2 using the format path1;path2 or path1path2.
RUBYOPT     # Command-line options passed to Ruby interpreter. Ignored in taint mode (Where $SAFE is greater than 0).
RUBYPATH    # With -S option, search path for Ruby programs. Takes precedence over PATH. Ignored in taint mode (where $SAFE is greater than 0).
RUBYSHELL   # Specifies shell for spawned processes. If not set, SHELL or COMSPEC are checked.

JRuby and RBX might have few more, @headius & @brixen - can you fill in?

ysbaddaden commented 9 years ago

Thanks for the hint @mpapis ! I'll try with a blacklist solution.

headius commented 9 years ago

JRuby should obey the RUBY* env vars. We have also heard of bugs when there's no HOME set, but it's uncommon.

Additional for JRuby:

JRUBY_OPTS JAVA_OPTS

I'd have to audit the codebase to get a complete list.

brixen commented 9 years ago

Anything prefixed with RBX (eg RBXOPT) could affect Rubinius. We can't give you a definitive set because we'll add them whenever we want. But we'll prefix any we depend on.

mpapis commented 9 years ago

ah I would have forgotten, there is set of variables starting with BUNDLE that might affect bundler/rails

ysbaddaden commented 9 years ago

Thanks for the input. I'll try a nicer cleanup of shell environment. Right now I only let $HOME slip by, and I didn't break much projects (only $HOME was required once) —developers can use the sourced ~/.praxconfig if they need anything globally or myapp/.praxrc or myapp/.env for project specifics.