diff --git a/ChangeLog b/ChangeLog index 26e1e21b7f..86289389c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat May 21 00:36:32 2016 Nobuyoshi Nakada + + * process.c (rb_execarg_commandline): build command line string + from argument vector in rb_execarg. + [ruby-core:75611] [Bug #12398] + Fri May 20 23:25:42 2016 Kazuki Yamaguchi * ext/openssl/ossl.c (ossl_pem_passwd_value): Added. Convert the diff --git a/io.c b/io.c index 7e6ca89038..f4cc940865 100644 --- a/io.c +++ b/io.c @@ -5886,6 +5886,8 @@ rb_execarg_fixup_v(VALUE execarg_obj) rb_execarg_parent_start(execarg_obj); return Qnil; } +#else +char *rb_execarg_commandline(const struct rb_execarg *eargp, VALUE *prog); #endif static VALUE @@ -5933,10 +5935,6 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, int write_fd = -1; #if !defined(HAVE_WORKING_FORK) const char *cmd = 0; -#if !defined(HAVE_SPAWNV) - int argc; - VALUE *argv; -#endif if (prog) cmd = StringValueCStr(prog); @@ -6065,10 +6063,7 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, fd = arg.pair[1]; } #else - if (argc) { - prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" ")); - cmd = StringValueCStr(prog); - } + cmd = rb_execarg_commandline(eargp, &prog); if (!NIL_P(execarg_obj)) { rb_execarg_parent_start(execarg_obj); rb_execarg_run_options(eargp, sargp, NULL, 0); diff --git a/process.c b/process.c index 1147205ebd..ae627ea5a0 100644 --- a/process.c +++ b/process.c @@ -3902,6 +3902,29 @@ rb_syswait(rb_pid_t pid) rb_waitpid(pid, &status, 0); } +#if !defined HAVE_WORKING_FORK && !defined HAVE_SPAWNV +char * +rb_execarg_commandline(const struct rb_execarg *eargp, VALUE *prog) +{ + VALUE cmd = *prog; + if (eargp && !eargp->use_shell) { + VALUE str = eargp->invoke.cmd.argv_str; + VALUE buf = eargp->invoke.cmd.argv_buf; + char *p, **argv = ARGVSTR2ARGV(str); + long i, argc = ARGVSTR2ARGC(str); + const char *start = RSTRING_PTR(buf); + cmd = rb_str_new(start, RSTRING_LEN(buf)); + p = RSTRING_PTR(cmd); + for (i = 1; i < argc; ++i) { + p[argv[i] - start - 1] = ' '; + } + *prog = cmd; + return p; + } + return StringValueCStr(*prog); +} +#endif + static rb_pid_t rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen) { @@ -3909,6 +3932,9 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen) #if !defined HAVE_WORKING_FORK || USE_SPAWNV VALUE prog; struct rb_execarg sarg; +# if !defined HAVE_SPAWNV + int status; +# endif #endif #if defined HAVE_WORKING_FORK && !USE_SPAWNV @@ -3935,12 +3961,7 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen) if (pid == -1) rb_last_status_set(0x7f << 8, 0); # else - if (!eargp->use_shell) { - char **argv = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str); - int argc = ARGVSTR2ARGC(eargp->invoke.cmd.argv_str); - prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" ")); - } - status = system(StringValuePtr(prog)); + status = system(rb_execarg_commandline(eargp, &prog)); rb_last_status_set((status & 0xff) << 8, 0); pid = 1; /* dummy */ # endif