diff --git a/ChangeLog b/ChangeLog index bd8ec43842..c48f0476e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon May 24 08:16:02 2010 Nobuyoshi Nakada + + * process.c (rb_f_spawn): use correct command name for the error + message. [ruby-dev:41395] + Sun May 23 17:48:39 2010 Nobuyoshi Nakada * ext/openssl/lib/openssl/x509-internal.rb, lib/forwardable.rb, diff --git a/process.c b/process.c index f262f73fd9..9e52392320 100644 --- a/process.c +++ b/process.c @@ -2850,37 +2850,40 @@ rb_syswait(rb_pid_t pid) } } +static VALUE +rb_exec_arg_prepare(struct rb_exec_arg *earg, int argc, VALUE *argv, int default_close_others) +{ + VALUE prog = rb_exec_arg_init(argc, argv, TRUE, earg); + if (NIL_P(rb_ary_entry(earg->options, EXEC_OPTION_CLOSE_OTHERS))) { + VALUE v = default_close_others ? Qtrue : Qfalse; + rb_exec_arg_addopt(earg, ID2SYM(rb_intern("close_others")), v); + } + rb_exec_arg_fixup(earg); + return prog; +} + static rb_pid_t -rb_spawn_internal(int argc, VALUE *argv, int default_close_others, - char *errmsg, size_t errmsg_buflen) +rb_spawn_process(struct rb_exec_arg *earg, VALUE prog, char *errmsg, size_t errmsg_buflen) { rb_pid_t pid; #if defined HAVE_FORK || !defined HAVE_SPAWNV int status; #endif - VALUE prog; - struct rb_exec_arg earg; #if !defined HAVE_FORK struct rb_exec_arg sarg; + int argc; + VALUE *argv; #endif - prog = rb_exec_arg_init(argc, argv, TRUE, &earg); - if (NIL_P(rb_ary_entry(earg.options, EXEC_OPTION_CLOSE_OTHERS))) { - VALUE v = default_close_others ? Qtrue : Qfalse; - rb_exec_arg_addopt(&earg, ID2SYM(rb_intern("close_others")), v); - } - rb_exec_arg_fixup(&earg); - #if defined HAVE_FORK - pid = rb_fork_err(&status, rb_exec_atfork, &earg, earg.redirect_fds, errmsg, errmsg_buflen); - if (prog && earg.argc) earg.argv[0] = prog; + pid = rb_fork_err(&status, rb_exec_atfork, earg, earg->redirect_fds, errmsg, errmsg_buflen); #else - if (rb_run_exec_options_err(&earg, &sarg, errmsg, errmsg_buflen) < 0) { + if (rb_run_exec_options_err(earg, &sarg, errmsg, errmsg_buflen) < 0) { return -1; } - argc = earg.argc; - argv = earg.argv; + argc = earg->argc; + argv = earg->argv; if (prog && argc) argv[0] = prog; # if defined HAVE_SPAWNV if (!argc) { @@ -2904,6 +2907,15 @@ rb_spawn_internal(int argc, VALUE *argv, int default_close_others, return pid; } +static rb_pid_t +rb_spawn_internal(int argc, VALUE *argv, int default_close_others, + char *errmsg, size_t errmsg_buflen) +{ + struct rb_exec_arg earg; + VALUE prog = rb_exec_arg_prepare(&earg, argc, argv, default_close_others); + return rb_spawn_process(&earg, prog, errmsg, errmsg_buflen); +} + rb_pid_t rb_spawn_err(int argc, VALUE *argv, char *errmsg, size_t errmsg_buflen) { @@ -3218,12 +3230,15 @@ rb_f_spawn(int argc, VALUE *argv) { rb_pid_t pid; char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' }; + struct rb_exec_arg earg; - pid = rb_spawn_err(argc, argv, errmsg, sizeof(errmsg)); + pid = rb_spawn_process(&earg, rb_exec_arg_prepare(&earg, argc, argv, TRUE), errmsg, sizeof(errmsg)); if (pid == -1) { - if (errmsg[0] == '\0') - rb_sys_fail(RSTRING_PTR(argv[0])); - rb_sys_fail(errmsg); + const char *prog = errmsg; + if (!prog[0] && !(prog = earg.prog) && earg.argc) { + prog = RSTRING_PTR(earg.argv[0]); + } + rb_sys_fail(prog); } #if defined(HAVE_FORK) || defined(HAVE_SPAWNV) return PIDT2NUM(pid); diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 9fc9f0c603..4d88be5843 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -236,6 +236,17 @@ class TestProcess < Test::Unit::TestCase system({"F=O"=>"BAR"}, *TRUECOMMAND) } + with_tmpchdir {|d| + prog = "#{d}/notexist" + e = assert_raise(Errno::ENOENT) { + Process.wait Process.spawn({"FOO"=>"BAR"}, prog) + } + assert_equal(prog, e.message.sub(/.* - /, '')) + e = assert_raise(Errno::ENOENT) { + Process.wait Process.spawn({"FOO"=>"BAR"}, [prog, "blar"]) + } + assert_equal(prog, e.message.sub(/.* - /, '')) + } h = {} cmd = [h, RUBY] (ENV.keys + MANDATORY_ENVS).each do |k| diff --git a/version.h b/version.h index e561554037..fd6f190e91 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_RELEASE_DATE "2010-05-23" +#define RUBY_RELEASE_DATE "2010-05-24" #define RUBY_PATCHLEVEL -1 #define RUBY_BRANCH_NAME "trunk" @@ -8,7 +8,7 @@ #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_YEAR 2010 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 23 +#define RUBY_RELEASE_DAY 24 #include "ruby/version.h"