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

* process.c (rb_f_spawn): use correct command name for the error

message.  [ruby-dev:41395]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-05-23 23:16:09 +00:00
parent b4f1eaa493
commit d837ce5eda
4 changed files with 53 additions and 22 deletions

View file

@ -1,3 +1,8 @@
Mon May 24 08:16:02 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <nobu@ruby-lang.org>
* ext/openssl/lib/openssl/x509-internal.rb, lib/forwardable.rb,

View file

@ -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);

View file

@ -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|

View file

@ -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"