summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--process.c40
-rw-r--r--test/ruby/test_process.rb10
3 files changed, 35 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 616a0044f7..0f1bfd6c76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Mar 3 22:51:46 2012 Tanaka Akira <akr@fsij.org>
+
+ * process.c (rb_run_exec_options_err): chdir at last to interpret
+ relative pathnames from the current directory of the parent process.
+
Sat Mar 3 12:20:44 2012 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_strftime.c: reassigned some variables.
diff --git a/process.c b/process.c
index ba7bee19f0..2323195f8f 100644
--- a/process.c
+++ b/process.c
@@ -2367,20 +2367,6 @@ rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char
}
}
- obj = rb_ary_entry(options, EXEC_OPTION_CHDIR);
- if (!NIL_P(obj)) {
- if (!NIL_P(soptions)) {
- char *cwd = my_getcwd();
- rb_ary_store(soptions, EXEC_OPTION_CHDIR,
- hide_obj(rb_str_new2(cwd)));
- xfree(cwd);
- }
- if (chdir(RSTRING_PTR(obj)) == -1) {
- ERRMSG("chdir");
- return -1;
- }
- }
-
obj = rb_ary_entry(options, EXEC_OPTION_UMASK);
if (!NIL_P(obj)) {
mode_t mask = NUM2MODET(obj);
@@ -2424,6 +2410,20 @@ rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char
return -1;
}
+ obj = rb_ary_entry(options, EXEC_OPTION_CHDIR);
+ if (!NIL_P(obj)) {
+ if (!NIL_P(soptions)) {
+ char *cwd = my_getcwd();
+ rb_ary_store(soptions, EXEC_OPTION_CHDIR,
+ hide_obj(rb_str_new2(cwd)));
+ xfree(cwd);
+ }
+ if (chdir(RSTRING_PTR(obj)) == -1) {
+ ERRMSG("chdir");
+ return -1;
+ }
+ }
+
return 0;
}
@@ -3141,8 +3141,6 @@ rb_f_system(int argc, VALUE *argv)
* resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit.
* :rlimit_resourcename => limit
* :rlimit_resourcename => [cur_limit, max_limit]
- * current directory:
- * :chdir => str
* umask:
* :umask => int
* redirection:
@@ -3165,6 +3163,8 @@ rb_f_system(int argc, VALUE *argv)
* io : the file descriptor specified as io.fileno
* file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
* :close_others => true : don't inherit
+ * current directory:
+ * :chdir => str
*
* If a hash is given as +env+, the environment is
* updated by +env+ before <code>exec(2)</code> in the child process.
@@ -3208,10 +3208,6 @@ rb_f_system(int argc, VALUE *argv)
* pid = spawn(command, :rlimit_core=>max) # enable core dump
* pid = spawn(command, :rlimit_core=>0) # never dump core.
*
- * The <code>:chdir</code> key in +options+ specifies the current directory.
- *
- * pid = spawn(command, :chdir=>"/var/tmp")
- *
* The <code>:umask</code> key in +options+ specifies the umask.
*
* pid = spawn(command, :umask=>077)
@@ -3291,6 +3287,10 @@ rb_f_system(int argc, VALUE *argv)
* io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
* p io.read #=> "out\nerr\n"
*
+ * The <code>:chdir</code> key in +options+ specifies the current directory.
+ *
+ * pid = spawn(command, :chdir=>"/var/tmp")
+ *
* spawn closes all non-standard unspecified descriptors by default.
* The "standard" descriptors are 0, 1 and 2.
* This behavior is specified by :close_others option.
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index a1c5822417..3dab8e0bfa 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -327,6 +327,16 @@ class TestProcess < Test::Unit::TestCase
}
end
+ def test_execopts_open_chdir
+ with_tmpchdir {|d|
+ Dir.mkdir "foo"
+ system(*PWD, :chdir => "foo", :out => "open_chdir_test")
+ assert(File.exist?("open_chdir_test"))
+ assert(!File.exist?("foo/open_chdir_test"))
+ assert_equal("#{d}/foo", File.read("open_chdir_test").chomp)
+ }
+ end
+
UMASK = [RUBY, '-e', 'printf "%04o\n", File.umask']
def test_execopts_umask