diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-06 11:49:30 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-06 11:49:30 +0000 |
commit | 70232e400cae3509b6b816e3c8beed8be6f55dd7 (patch) | |
tree | 795c68ef6e0d0fd7cca79c3d794d31a3cbdf59cd | |
parent | 7685837427e60770d7228cc1d3db97257521a606 (diff) | |
download | ruby-70232e400cae3509b6b816e3c8beed8be6f55dd7.tar.gz |
* process.c (proc_exec_v): don't call dln_find_exe_r here because it
is not async-signal-safe and proc_exec_v is called in a child
process.
command_abspath field of rb_exec_arg.
(rb_exec_fillarg): call dln_find_exe_r and set command_abspath.
(rb_exec_err): Give the absolute path of the invoking command for
proc_exec_v, instead of the command name.
* internal.h: add command_abspath field for rb_exec_arg.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | process.c | 22 |
3 files changed, 29 insertions, 6 deletions
@@ -1,3 +1,15 @@ +Wed Jun 6 20:45:08 2012 Tanaka Akira <akr@fsij.org> + + * process.c (proc_exec_v): don't call dln_find_exe_r here because it + is not async-signal-safe and proc_exec_v is called in a child + process. + command_abspath field of rb_exec_arg. + (rb_exec_fillarg): call dln_find_exe_r and set command_abspath. + (rb_exec_err): Give the absolute path of the invoking command for + proc_exec_v, instead of the command name. + + * internal.h: add command_abspath field for rb_exec_arg. + Wed Jun 6 20:08:01 2012 Tanaka Akira <akr@fsij.org> * process.c (try_with_sh): take envp argument. diff --git a/internal.h b/internal.h index 6a988c95c6..9ef4fba661 100644 --- a/internal.h +++ b/internal.h @@ -167,6 +167,7 @@ struct rb_exec_arg { } sh; struct { VALUE command_name; + VALUE command_abspath; /* full path string or nil */ VALUE argv_str; VALUE argv_buf; } cmd; @@ -1077,7 +1077,6 @@ proc_exec_v(const char *prog, VALUE argv_str, VALUE envp_str) UNREACHABLE; #else char **argv; - char fbuf[MAXPATHLEN]; char **envp; # if defined(__EMX__) || defined(OS2) char **new_argv = NULL; @@ -1085,9 +1084,6 @@ proc_exec_v(const char *prog, VALUE argv_str, VALUE envp_str) argv = ARGVSTR2ARGV(argv_str); - if (!prog) - prog = argv[0]; - prog = dln_find_exe_r(prog, 0, fbuf, sizeof(fbuf)); /* xxx: not async-signal-safe because getenv(), strdup(), etc. */ if (!prog) { errno = ENOENT; return -1; @@ -1767,6 +1763,8 @@ static void rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, struct rb_exec_arg *e) { VALUE options; + char fbuf[MAXPATHLEN]; + MEMZERO(e, struct rb_exec_arg, 1); options = hide_obj(rb_ary_new()); e->options = options; @@ -1823,6 +1821,15 @@ rb_exec_fillarg(VALUE prog, int argc, VALUE *argv, VALUE env, VALUE opthash, str } #endif + if (!e->use_shell) { + char *abspath; + abspath = dln_find_exe_r(RSTRING_PTR(e->invoke.cmd.command_name), 0, fbuf, sizeof(fbuf)); + if (abspath) + e->invoke.cmd.command_abspath = rb_str_new_cstr(abspath); + else + e->invoke.cmd.command_abspath = Qnil; + } + if (!e->use_shell && !e->invoke.cmd.argv_buf) { int i; VALUE argv_buf; @@ -2604,7 +2611,10 @@ rb_exec_err(const struct rb_exec_arg *e, char *errmsg, size_t errmsg_buflen) rb_proc_exec_e(RSTRING_PTR(e->invoke.sh.shell_script), e->envp_str); /* not async-signal-safe because after_exec. */ } else { - proc_exec_v(RSTRING_PTR(e->invoke.cmd.command_name), e->invoke.cmd.argv_str, e->envp_str); /* not async-signal-safe because dln_find_exe_r */ + char *abspath = NULL; + if (!NIL_P(e->invoke.cmd.command_abspath)) + abspath = RSTRING_PTR(e->invoke.cmd.command_abspath); + proc_exec_v(abspath, e->invoke.cmd.argv_str, e->envp_str); /* async-signal-safe */ } #if !defined(HAVE_FORK) preserving_errno(rb_run_exec_options_err(sargp, NULL, errmsg, errmsg_buflen)); @@ -2642,7 +2652,7 @@ static int rb_exec_atfork(void* arg, char *errmsg, size_t errmsg_buflen) { rb_thread_atfork_before_exec(); /* xxx: not async-signal-safe because it calls rb_thread_atfork_internal which calls st_insert, etc. */ - return rb_exec_err(arg, errmsg, errmsg_buflen); /* not async-signal-safe because after_exec and dln_find_exe_r */ + return rb_exec_err(arg, errmsg, errmsg_buflen); /* not async-signal-safe because after_exec */ } #endif |