Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 73808fbbb343
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 85cb4e96ff2e
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 12, 2018

  1. Copy the full SHA
    686fca1 View commit details
  2. Copy the full SHA
    85cb4e9 View commit details
Showing with 27 additions and 12 deletions.
  1. +13 −2 core/src/main/java/org/jruby/util/ShellLauncher.java
  2. +14 −10 core/src/main/java/org/jruby/util/io/PopenExecutor.java
15 changes: 13 additions & 2 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
@@ -411,14 +411,25 @@ private static File findPathFile(Ruby runtime, String fname, String[] path, bool
return pathFile;
}

// MRI: Hopefully close to dln_find_exe_r used by popen logic
public static File findPathExecutable(Ruby runtime, String fname) {
RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
IRubyObject pathObject = env.op_aref(runtime.getCurrentContext(), RubyString.newString(runtime, PATH_ENV));
String[] pathNodes = null;
return findPathExecutable(runtime, fname, pathObject);
}

// MRI: Hopefully close to dln_find_exe_r used by popen logic
public static File findPathExecutable(Ruby runtime, String fname, IRubyObject pathObject) {
String[] pathNodes;

if (pathObject == null || pathObject.isNil()) {
RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
pathObject = env.op_aref(runtime.getCurrentContext(), RubyString.newString(runtime, PATH_ENV));
}

if (pathObject == null) {
pathNodes = DEFAULT_PATH; // ASSUME: not modified by callee
}

else {
String pathSeparator = System.getProperty("path.separator");
String path = pathObject.toString();
24 changes: 14 additions & 10 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ long procSpawnCmdInternal(Ruby runtime, String[] argv, String prog, ExecArg earg

if (prog == null)
prog = argv[0];
prog = dlnFindExeR(runtime, prog, null);
prog = dlnFindExeR(runtime, prog, eargp.path_env);
if (prog == null) {
errno = Errno.ENOENT;
return -1;
@@ -222,7 +222,7 @@ long procSpawnCmd(Ruby runtime, String[] argv, String prog, ExecArg eargp) {
long procSpawnSh(Ruby runtime, String str, ExecArg eargp) {
long status;

String shell = dlnFindExeR(runtime, "sh", null);
String shell = dlnFindExeR(runtime, "sh", eargp.path_env);

// System.out.println("before: " + shell + ", fa=" + eargp.fileActions + ", a=" + eargp.attributes + ", argv=" + Arrays.asList("sh", "-c", str));
status = runtime.getPosix().posix_spawnp(
@@ -323,10 +323,11 @@ public static IRubyObject popen(ThreadContext context, IRubyObject[] argv, RubyC
}

static void execargSetenv(ThreadContext context, Ruby runtime, ExecArg eargp, IRubyObject env) {
eargp.env_modification = !env.isNil() ? checkExecEnv(context, (RubyHash)env) : null;
eargp.env_modification = !env.isNil() ? checkExecEnv(context, (RubyHash)env, eargp) : null;
}

public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
// MRI: rb_check_exec_env
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash, ExecArg pathArg) {
Ruby runtime = context.runtime;
RubyArray env;

@@ -346,6 +347,10 @@ public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
key = key.convertToString().export(context);
if (!val.isNil()) val = val.convertToString().export(context);

if (key.convertToString().toString().equalsIgnoreCase("PATH")) {
pathArg.path_env = val;
}

env.push(runtime.newArray(key, val));
}

@@ -1858,7 +1863,7 @@ else if (!eargp.chdir_given()) { // only if :chdir is not specified
}

if (!env.isNil()) {
eargp.env_modification = checkExecEnv(context, (RubyHash) env);
eargp.env_modification = checkExecEnv(context, (RubyHash) env, eargp);
}

prog = prog.export(context);
@@ -1958,7 +1963,7 @@ else if (progByteList.get(p) == '/'){

if (!eargp.use_shell) {
String abspath;
abspath = dlnFindExeR(runtime, eargp.command_name.toString(), null);
abspath = dlnFindExeR(runtime, eargp.command_name.toString(), eargp.path_env);
if (abspath != null)
eargp.command_abspath = StringSupport.checkEmbeddedNulls(runtime, RubyString.newString(runtime, abspath));
else
@@ -2000,10 +2005,8 @@ public int compare(String o1, String o2) {

}

private static String dlnFindExeR(Ruby runtime, String fname, String path) {
if (path != null) throw new RuntimeException("BUG: dln_find_exe_r with path is not supported yet");
// FIXME: need to reencode path as same
File exePath = ShellLauncher.findPathExecutable(runtime, fname);
private static String dlnFindExeR(Ruby runtime, String fname, IRubyObject path) {
File exePath = ShellLauncher.findPathExecutable(runtime, fname, path);
return exePath != null ? exePath.getAbsolutePath() : null;
}

@@ -2036,6 +2039,7 @@ public static class ExecArg {
String chdir_dir;
List<SpawnFileAction> fileActions = new ArrayList();
List<SpawnAttribute> attributes = new ArrayList();
IRubyObject path_env;

boolean pgroup_given() {
return (flags & 0x1) != 0;