From 61c148723d128db48196a7f46e9ba2b7e704fc37 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 3 Mar 2012 13:53:53 +0000 Subject: * 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 --- process.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'process.c') 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 exec(2) 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 :chdir key in +options+ specifies the current directory. - * - * pid = spawn(command, :chdir=>"/var/tmp") - * * The :umask 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 :chdir 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. -- cgit v1.2.3