From 217f31a899c58a2529718e9dca253a241c6cfcbc Mon Sep 17 00:00:00 2001 From: Tobias Crawley Date: Thu, 21 Jul 2011 10:12:13 -0400 Subject: [PATCH] Allow disabling ENV write-through to the real environment [JRUBY-5934] This adds updateNativeENVEnabled to RubyInstanceConfig with a default of true. If it is true and jruby.native.enabled is also true, any modifications to the runtime's ruby ENV will be reflected in the system env via POSIX. Otherwise, the modifications are not written through. This setting has not yet been pushed out to the embedding API's (ScriptingContainer & JRubyEngine), nor has it been documented. --- src/org/jruby/RubyGlobal.java | 17 +++--- src/org/jruby/RubyInstanceConfig.java | 14 ++++- test/org/jruby/test/TestRuby.java | 55 ++++++++++++++++++- .../jruby/test/TestRubyInstanceConfig.java | 1 + 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/org/jruby/RubyGlobal.java b/src/org/jruby/RubyGlobal.java index fcb2bd04b95..f3bc9ffba29 100644 --- a/src/org/jruby/RubyGlobal.java +++ b/src/org/jruby/RubyGlobal.java @@ -73,8 +73,8 @@ public class RubyGlobal { */ public static class CaseInsensitiveStringOnlyRubyHash extends StringOnlyRubyHash { - public CaseInsensitiveStringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) { - super(runtime, valueMap, defaultValue, true); + public CaseInsensitiveStringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) { + super(runtime, valueMap, defaultValue, updateRealENV); } @Override @@ -382,11 +382,14 @@ private static void defineGlobalEnvConstants(Ruby runtime) { environmentVariableMap = new HashMap(); } - CaseInsensitiveStringOnlyRubyHash h1 = new CaseInsensitiveStringOnlyRubyHash(runtime, - environmentVariableMap, runtime.getNil()); - h1.getSingletonClass().defineAnnotatedMethods(CaseInsensitiveStringOnlyRubyHash.class); - runtime.defineGlobalConstant("ENV", h1); - runtime.setENV(h1); + CaseInsensitiveStringOnlyRubyHash env = new CaseInsensitiveStringOnlyRubyHash(runtime, + environmentVariableMap, + runtime.getNil(), + RubyInstanceConfig.nativeEnabled && + runtime.getInstanceConfig().isUpdateNativeENVEnabled() ); + env.getSingletonClass().defineAnnotatedMethods(CaseInsensitiveStringOnlyRubyHash.class); + runtime.defineGlobalConstant("ENV", env); + runtime.setENV(env); // Define System.getProperties() in ENV_JAVA Map systemProps = environment.getSystemPropertiesMap(runtime); diff --git a/src/org/jruby/RubyInstanceConfig.java b/src/org/jruby/RubyInstanceConfig.java index 0717afd5efb..9175c73da8e 100644 --- a/src/org/jruby/RubyInstanceConfig.java +++ b/src/org/jruby/RubyInstanceConfig.java @@ -251,7 +251,8 @@ public enum ProfilingMode { private String threadDumpSignal = null; private boolean hardExit = false; private boolean disableGems = false; - + private boolean updateNativeENVEnabled = true; + private int safeLevel = 0; private String jrubyHome; @@ -427,6 +428,7 @@ public RubyInstanceConfig(RubyInstanceConfig parentConfig) { runRubyInProcess = parentConfig.runRubyInProcess; excludedMethods = parentConfig.excludedMethods; threadDumpSignal = parentConfig.threadDumpSignal; + updateNativeENVEnabled = parentConfig.updateNativeENVEnabled; classCache = new ClassCache