hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1077576 - in /hadoop/common/branches/branch-0.20-security-patches/src: mapred/org/apache/hadoop/mapred/TaskRunner.java test/org/apache/hadoop/mapred/TestTaskEnvironment.java
Date Fri, 04 Mar 2011 04:30:52 GMT
Author: omalley
Date: Fri Mar  4 04:30:52 2011
New Revision: 1077576

URL: http://svn.apache.org/viewvc?rev=1077576&view=rev
Log:
commit 225283ea86afdc51079fd7066f48ff8da1125524
Author: Arun C Murthy <acmurthy@apache.org>
Date:   Tue Jul 20 23:58:16 2010 -0700

    HADOOP-5981. Fix variable substitution during parsing of child environment variables.
Contributed by Krishna Ramachandran.
    
    +++ b/YAHOO-CHANGES.txt
    +    HADOOP-5981. Fix variable substitution during parsing of child environment
    +    variables. (Krishna Ramachandran via acmurthy)
    +

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/TaskRunner.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapred/TestTaskEnvironment.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/TaskRunner.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/TaskRunner.java?rev=1077576&r1=1077575&r2=1077576&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/TaskRunner.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/TaskRunner.java
Fri Mar  4 04:30:52 2011
@@ -562,7 +562,8 @@ abstract class TaskRunner extends Thread
     hadoopClientOpts = hadoopClientOpts + "-Dhadoop.tasklog.taskid=" + taskid
                        + " -Dhadoop.tasklog.iscleanup=" + t.isTaskCleanupTask()
                        + " -Dhadoop.tasklog.totalLogFileSize=" + logSize;
-    env.put("HADOOP_CLIENT_OPTS", "\"" + hadoopClientOpts + "\"");
+    // following line is a backport from jira MAPREDUCE-1286 
+    env.put("HADOOP_CLIENT_OPTS", hadoopClientOpts);
 
     // add the env variables passed by the user
     String mapredChildEnv = getChildEnv(conf);
@@ -588,7 +589,7 @@ abstract class TaskRunner extends Thread
    * @return
    * @throws Throwable
    */
-  private String setEnvFromInputString(String errorInfo, Map<String, String> env,
+  String setEnvFromInputString(String errorInfo, Map<String, String> env,
       String mapredChildEnv) throws Throwable {
     if (mapredChildEnv != null && mapredChildEnv.length() > 0) {
       String childEnvs[] = mapredChildEnv.split(",");
@@ -596,6 +597,7 @@ abstract class TaskRunner extends Thread
         try {
           String[] parts = cEnv.split("="); // split on '='
           String value = env.get(parts[0]);
+          
           if (value != null) {
             // replace $env with the child's env constructed by tt's
             // example LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp
@@ -609,9 +611,16 @@ abstract class TaskRunner extends Thread
               // the env key is present in the tt's env
               value = parts[1].replace("$" + parts[0], value);
             } else {
-              // the env key is note present anywhere .. simply set it
-              // example X=$X:/tmp or X=/tmp
-              value = parts[1].replace("$" + parts[0], "");
+              // check for simple variable substitution
+              // for e.g. ROOT=$HOME
+              String envValue = System.getenv(parts[1].substring(1)); 
+              if (envValue != null) {
+                value = envValue;
+              } else {
+                // the env key is note present anywhere .. simply set it
+                // example X=$X:/tmp or X=/tmp
+                value = parts[1].replace("$" + parts[0], "");
+              }
             }
           }
           env.put(parts[0], value);

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapred/TestTaskEnvironment.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapred/TestTaskEnvironment.java?rev=1077576&r1=1077575&r2=1077576&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapred/TestTaskEnvironment.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/mapred/TestTaskEnvironment.java
Fri Mar  4 04:30:52 2011
@@ -90,6 +90,7 @@ public class TestTaskEnvironment {
   public void testTaskEnv() throws Throwable {
     ttConf.set("mapreduce.admin.user.shell", "/bin/testshell");
     ttConf.set("mapreduce.admin.user.env", "key1=value1,key2=value2");
+    ttConf.set("mapred.child.env", "ROOT=$HOME");
     final Map<String, String> env = new HashMap<String, String>();
     String user = "test";
     JobConf taskConf = new JobConf(ttConf);
@@ -99,7 +100,9 @@ public class TestTaskEnvironment {
     TaskInProgress tip = tt.new TaskInProgress(task, taskConf);
     final TaskRunner taskRunner = task.createRunner(tt, tip);
     String errorInfo = "Child error";
+    String mapredChildEnv = taskRunner.getChildEnv(taskConf);
     taskRunner.updateUserLoginEnv(errorInfo, user, taskConf, env);
+    taskRunner.setEnvFromInputString(errorInfo, env, mapredChildEnv);
 
     final Vector<String> vargs = new Vector<String>(1);
     File pidFile = new File(TEST_DIR, "pid");
@@ -120,5 +123,8 @@ public class TestTaskEnvironment {
     assertTrue(jvmenvmap.containsValue("value2"));
     assertTrue(javaOpts, javaOpts.contains("Xmx"));
     assertTrue(javaOpts, javaOpts.contains("IPv4"));
+    
+    String root = jvmenvmap.get("ROOT");
+    assertTrue(root, root.contentEquals(System.getenv("HOME")));
   }
 }



Mime
View raw message