|
@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
|
+import org.apache.hadoop.security.alias.AbstractJavaKeyStoreProvider;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -362,6 +363,9 @@ public abstract class Shell {
|
|
/** If or not script timed out*/
|
|
/** If or not script timed out*/
|
|
private final AtomicBoolean timedOut = new AtomicBoolean(false);
|
|
private final AtomicBoolean timedOut = new AtomicBoolean(false);
|
|
|
|
|
|
|
|
+ /** Indicates if the parent env vars should be inherited or not*/
|
|
|
|
+ protected boolean inheritParentEnv = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Centralized logic to discover and validate the sanity of the Hadoop
|
|
* Centralized logic to discover and validate the sanity of the Hadoop
|
|
* home directory.
|
|
* home directory.
|
|
@@ -854,9 +858,16 @@ public abstract class Shell {
|
|
timedOut.set(false);
|
|
timedOut.set(false);
|
|
completed.set(false);
|
|
completed.set(false);
|
|
|
|
|
|
|
|
+ // Remove all env vars from the Builder to prevent leaking of env vars from
|
|
|
|
+ // the parent process.
|
|
|
|
+ if (!inheritParentEnv) {
|
|
|
|
+ builder.environment().clear();
|
|
|
|
+ }
|
|
|
|
+
|
|
if (environment != null) {
|
|
if (environment != null) {
|
|
builder.environment().putAll(this.environment);
|
|
builder.environment().putAll(this.environment);
|
|
}
|
|
}
|
|
|
|
+
|
|
if (dir != null) {
|
|
if (dir != null) {
|
|
builder.directory(this.dir);
|
|
builder.directory(this.dir);
|
|
}
|
|
}
|
|
@@ -1084,6 +1095,11 @@ public abstract class Shell {
|
|
this(execString, dir, env , 0L);
|
|
this(execString, dir, env , 0L);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public ShellCommandExecutor(String[] execString, File dir,
|
|
|
|
+ Map<String, String> env, long timeout) {
|
|
|
|
+ this(execString, dir, env , timeout, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Create a new instance of the ShellCommandExecutor to execute a command.
|
|
* Create a new instance of the ShellCommandExecutor to execute a command.
|
|
*
|
|
*
|
|
@@ -1096,10 +1112,12 @@ public abstract class Shell {
|
|
* environment is not modified.
|
|
* environment is not modified.
|
|
* @param timeout Specifies the time in milliseconds, after which the
|
|
* @param timeout Specifies the time in milliseconds, after which the
|
|
* command will be killed and the status marked as timed-out.
|
|
* command will be killed and the status marked as timed-out.
|
|
- * If 0, the command will not be timed out.
|
|
|
|
|
|
+ * If 0, the command will not be timed out.
|
|
|
|
+ * @param inheritParentEnv Indicates if the process should inherit the env
|
|
|
|
+ * vars from the parent process or not.
|
|
*/
|
|
*/
|
|
public ShellCommandExecutor(String[] execString, File dir,
|
|
public ShellCommandExecutor(String[] execString, File dir,
|
|
- Map<String, String> env, long timeout) {
|
|
|
|
|
|
+ Map<String, String> env, long timeout, boolean inheritParentEnv) {
|
|
command = execString.clone();
|
|
command = execString.clone();
|
|
if (dir != null) {
|
|
if (dir != null) {
|
|
setWorkingDirectory(dir);
|
|
setWorkingDirectory(dir);
|
|
@@ -1108,6 +1126,7 @@ public abstract class Shell {
|
|
setEnvironment(env);
|
|
setEnvironment(env);
|
|
}
|
|
}
|
|
timeOutInterval = timeout;
|
|
timeOutInterval = timeout;
|
|
|
|
+ this.inheritParentEnv = inheritParentEnv;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|