JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-5934

Writing ENV[]= changes through to the real ENV (via POSIX) should be configurable per runtime

    Details

    • Type: New Feature New Feature
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.3
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Currently, any changes to ENV in any runtime get reflected in the real ENV. This isn't always desirable, especially in the case of embedded runtimes. I propose a per runtime setting or System property to disable this.

      I would be happy to implement this if the jruby team agrees that it would be useful.

      My current approach to disable this is:

      StringBuffer env_fix = new StringBuffer( "require 'java'" );
      env_fix.append( "update_real_env_attr = org.jruby.RubyGlobal::StringOnlyRubyHash.java_class.declared_fields.find { |f| f.name == 'updateRealENV' }\n" );
      env_fix.append( "update_real_env_attr.accessible = true\n" );
      env_fix.append( "update_real_env_attr.set_value(ENV.to_java, false)\n" );
      runtime.evalScriptlet( env_fix.toString() );
      

      And god bless JRuby for making even that so flippin' easy.

        Activity

        Hide
        Thomas E Enebo added a comment -

        Ah yes embedding. We followed MRI in how it handled setting envs, but that is not desirable in MVMs or in embedding in some cases. On the flip side of this coin, I think if jruby.native.enabled=true then it should do this by default. Otherwise native calls (e.g. Kernel.exec() won't see those new ENVs <--- only works native on windows as of 1.6.3).

        A property (you cancadd it to RubyInstanceConfig) like jruby.native.env=true maybe? Then it could be disabled when you know you don't want it.

        Although not part of this bug I have also wondered how granular we should make some features like native method support. It seems like we are missing a more systemic way of controlling some of these all-or-nothing features.

        Show
        Thomas E Enebo added a comment - Ah yes embedding. We followed MRI in how it handled setting envs, but that is not desirable in MVMs or in embedding in some cases. On the flip side of this coin, I think if jruby.native.enabled=true then it should do this by default. Otherwise native calls (e.g. Kernel.exec() won't see those new ENVs <--- only works native on windows as of 1.6.3). A property (you cancadd it to RubyInstanceConfig) like jruby.native.env=true maybe? Then it could be disabled when you know you don't want it. Although not part of this bug I have also wondered how granular we should make some features like native method support. It seems like we are missing a more systemic way of controlling some of these all-or-nothing features.
        Hide
        Tobias Crawley added a comment -

        I'll add a flag to RubyInstanceConfig (mayhap updateNativeENV) that defaults to true, and ignore the flag if jruby.native.enabled=false, in which case the native ENV will not be updated. If any other native bits bite us in the future, I'd be happy to look into a more granular way to control them.

        Show
        Tobias Crawley added a comment - I'll add a flag to RubyInstanceConfig (mayhap updateNativeENV) that defaults to true, and ignore the flag if jruby.native.enabled=false, in which case the native ENV will not be updated. If any other native bits bite us in the future, I'd be happy to look into a more granular way to control them.
        Hide
        Tobias Crawley added a comment -

        I've implemented the bulk of this, and submitted a pull request (https://github.com/jruby/jruby/pull/51). I haven't yet documented it, since I wasn't sure where that should happen. I also haven't exposed it to the RedBridge classes, though it is available there via the instanceConfig. Let me know if you want any of this implemented differently.

        Show
        Tobias Crawley added a comment - I've implemented the bulk of this, and submitted a pull request ( https://github.com/jruby/jruby/pull/51 ). I haven't yet documented it, since I wasn't sure where that should happen. I also haven't exposed it to the RedBridge classes, though it is available there via the instanceConfig. Let me know if you want any of this implemented differently.
        Hide
        Nick Sieger added a comment -

        Fixed in 30647a5e on master.

        Show
        Nick Sieger added a comment - Fixed in 30647a5e on master.
        Hide
        Thomas E Enebo added a comment -

        This should be safe for 1.6 branch too since this is addressing behavior changed after 1.6.0.

        Show
        Thomas E Enebo added a comment - This should be safe for 1.6 branch too since this is addressing behavior changed after 1.6.0.
        Hide
        Tobias Crawley added a comment -

        This didn't make it into 1.6.4 - can we get it merged onto the 1.6 branch for 1.6.5?

        Show
        Tobias Crawley added a comment - This didn't make it into 1.6.4 - can we get it merged onto the 1.6 branch for 1.6.5?
        Hide
        Hiro Asari added a comment -

        Hi, Toby,

        I cherry-picked it to the 1.6 branch. https://github.com/jruby/jruby/commit/9b371c6eb3a3686df724f918f74a6cf39ce2644c

        Thanks.

        Show
        Hiro Asari added a comment - Hi, Toby, I cherry-picked it to the 1.6 branch. https://github.com/jruby/jruby/commit/9b371c6eb3a3686df724f918f74a6cf39ce2644c Thanks.
        Hide
        Tobias Crawley added a comment -

        Thanks Hiro.

        Show
        Tobias Crawley added a comment - Thanks Hiro.

          People

          • Assignee:
            Thomas E Enebo
            Reporter:
            Tobias Crawley
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: