1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (rb_run_exec_options_err): chdir at last to interpret

relative pathnames from the current directory of the parent process.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2012-03-03 13:53:53 +00:00
parent cb5217088b
commit 61c148723d
3 changed files with 35 additions and 20 deletions

View file

@ -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> Sat Mar 3 12:20:44 2012 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_strftime.c: reassigned some variables. * ext/date/date_strftime.c: reassigned some variables.

View file

@ -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); obj = rb_ary_entry(options, EXEC_OPTION_UMASK);
if (!NIL_P(obj)) { if (!NIL_P(obj)) {
mode_t mask = NUM2MODET(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; 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; return 0;
} }
@ -3141,8 +3141,6 @@ rb_f_system(int argc, VALUE *argv)
* resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit. * resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit.
* :rlimit_resourcename => limit * :rlimit_resourcename => limit
* :rlimit_resourcename => [cur_limit, max_limit] * :rlimit_resourcename => [cur_limit, max_limit]
* current directory:
* :chdir => str
* umask: * umask:
* :umask => int * :umask => int
* redirection: * redirection:
@ -3165,6 +3163,8 @@ rb_f_system(int argc, VALUE *argv)
* io : the file descriptor specified as io.fileno * io : the file descriptor specified as io.fileno
* file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not * file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
* :close_others => true : don't inherit * :close_others => true : don't inherit
* current directory:
* :chdir => str
* *
* If a hash is given as +env+, the environment is * If a hash is given as +env+, the environment is
* updated by +env+ before <code>exec(2)</code> in the child process. * 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=>max) # enable core dump
* pid = spawn(command, :rlimit_core=>0) # never dump core. * 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. * The <code>:umask</code> key in +options+ specifies the umask.
* *
* pid = spawn(command, :umask=>077) * 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]]) * io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
* p io.read #=> "out\nerr\n" * 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. * spawn closes all non-standard unspecified descriptors by default.
* The "standard" descriptors are 0, 1 and 2. * The "standard" descriptors are 0, 1 and 2.
* This behavior is specified by :close_others option. * This behavior is specified by :close_others option.

View file

@ -327,6 +327,16 @@ class TestProcess < Test::Unit::TestCase
} }
end 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'] UMASK = [RUBY, '-e', 'printf "%04o\n", File.umask']
def test_execopts_umask def test_execopts_umask