summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-06 00:58:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-06 00:58:49 +0000
commit4b7fd61a05aff71d5044f985ac3c7924bed9e403 (patch)
tree95ee5f29aa66e47ce671cbbc8fc32b53419af37d
parent840d23cb080c3f2d33dafe8de7f7feb04b0e0739 (diff)
process.c: PATH env in spawn
* process.c (rb_exec_fillarg): honor the given path environment variable. [ruby-core:53103] [Bug #8004] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--internal.h1
-rw-r--r--process.c32
-rw-r--r--test/ruby/test_process.rb10
4 files changed, 40 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 56a2976a2f..7f72c3004c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Nov 6 09:58:47 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * process.c (rb_exec_fillarg): honor the given path environment
+ variable. [ruby-core:53103] [Bug #8004]
+
Sun Nov 6 01:52:31 2016 Akira Matsuda <ronnie@dio.jp>
* lib/erb.rb: Alias regist_scanner to register_scanner
diff --git a/internal.h b/internal.h
index 7522122844..41e6f2ac66 100644
--- a/internal.h
+++ b/internal.h
@@ -1338,6 +1338,7 @@ struct rb_execarg {
VALUE fd_open;
VALUE fd_dup2_child;
VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
+ VALUE path_env;
VALUE chdir_dir;
};
diff --git a/process.c b/process.c
index b027be2bbe..d4d15a69b3 100644
--- a/process.c
+++ b/process.c
@@ -1350,6 +1350,7 @@ mark_exec_arg(void *ptr)
rb_gc_mark(eargp->fd_open);
rb_gc_mark(eargp->fd_dup2_child);
rb_gc_mark(eargp->env_modification);
+ rb_gc_mark(eargp->path_env);
rb_gc_mark(eargp->chdir_dir);
}
@@ -1929,12 +1930,19 @@ rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash)
return args[1];
}
+#ifdef ENV_IGNORECASE
+#define ENVMATCH(s1, s2) (STRCASECMP((s1), (s2)) == 0)
+#else
+#define ENVMATCH(n1, n2) (strcmp((n1), (n2)) == 0)
+#endif
+
static int
check_exec_env_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
{
VALUE key = (VALUE)st_key;
VALUE val = (VALUE)st_val;
- VALUE env = (VALUE)arg;
+ VALUE env = ((VALUE *)arg)[0];
+ VALUE *path = &((VALUE *)arg)[1];
char *k;
k = StringValueCStr(key);
@@ -1947,20 +1955,25 @@ check_exec_env_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
key = EXPORT_STR(key);
if (!NIL_P(val)) val = EXPORT_STR(val);
+ if (ENVMATCH(k, PATH_ENV)) {
+ *path = val;
+ }
rb_ary_push(env, hide_obj(rb_assoc_new(key, val)));
return ST_CONTINUE;
}
static VALUE
-rb_check_exec_env(VALUE hash)
+rb_check_exec_env(VALUE hash, VALUE *path)
{
- VALUE env;
+ VALUE env[2];
- env = hide_obj(rb_ary_new());
+ env[0] = hide_obj(rb_ary_new());
+ env[1] = Qfalse;
st_foreach(rb_hash_tbl_raw(hash), check_exec_env_i, (st_data_t)env);
+ *path = env[1];
- return env;
+ return env[0];
}
static VALUE
@@ -2066,7 +2079,7 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VAL
rb_check_exec_options(opthash, execarg_obj);
}
if (!NIL_P(env)) {
- env = rb_check_exec_env(env);
+ env = rb_check_exec_env(env, &eargp->path_env);
eargp->env_modification = env;
}
@@ -2190,7 +2203,10 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, VAL
if (!eargp->use_shell) {
const char *abspath;
- abspath = dln_find_exe_r(RSTRING_PTR(eargp->invoke.cmd.command_name), 0, fbuf, sizeof(fbuf));
+ const char *path_env = 0;
+ if (RTEST(eargp->path_env)) path_env = RSTRING_PTR(eargp->path_env);
+ abspath = dln_find_exe_r(RSTRING_PTR(eargp->invoke.cmd.command_name),
+ path_env, fbuf, sizeof(fbuf));
if (abspath)
eargp->invoke.cmd.command_abspath = rb_str_new_cstr(abspath);
else
@@ -2271,7 +2287,7 @@ void
rb_execarg_setenv(VALUE execarg_obj, VALUE env)
{
struct rb_execarg *eargp = rb_execarg_get(execarg_obj);
- env = !NIL_P(env) ? rb_check_exec_env(env) : Qfalse;
+ env = !NIL_P(env) ? rb_check_exec_env(env, &eargp->path_env) : Qfalse;
eargp->env_modification = env;
}
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 812af7a615..3921395466 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -316,6 +316,16 @@ class TestProcess < Test::Unit::TestCase
end
end
+ def test_execopt_env_path
+ bug8004 = '[ruby-core:53103] [Bug #8004]'
+ Dir.mktmpdir do |d|
+ open("#{d}/tmp_script.cmd", "w") {|f| f.puts ": ;"; f.chmod(0755)}
+ assert_not_nil(pid = Process.spawn({"PATH" => d}, "tmp_script.cmd"), bug8004)
+ wpid, st = Process.waitpid2(pid)
+ assert_equal([pid, true], [wpid, st.success?], bug8004)
+ end
+ end
+
def _test_execopts_env_popen(cmd)
message = cmd.inspect
IO.popen({"FOO"=>"BAR"}, cmd) {|io|