diff --git a/ChangeLog b/ChangeLog index 169b2dbe0c..d3fe3c7bba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Wed Jun 6 20:45:08 2012 Tanaka Akira + + * 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 * 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; diff --git a/process.c b/process.c index 1a419d65b7..995cc99b8f 100644 --- a/process.c +++ b/process.c @@ -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