From 876d4c4cc8f704029116b901ec4f696082a6ee30 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 26 Jun 2012 01:01:59 +0000 Subject: Revert r36213 "popen: shell commands with envvar" * io.c (rb_io_s_popen): revert r36213 "popen: shell commands with envvar" because it disabled to let single command bypass shell. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 7798ad5194..ade1f7bcaa 100644 --- a/io.c +++ b/io.c @@ -5692,30 +5692,35 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc return port; } -static int -is_popen_fork(VALUE prog) +static VALUE +pipe_open_v(int argc, VALUE *argv, const char *modestr, int fmode, convconfig_t *convconfig) { - if (RSTRING_LEN(prog) == 1 && RSTRING_PTR(prog)[0] == '-') { -#if !defined(HAVE_FORK) - rb_raise(rb_eNotImpError, - "fork() function is unimplemented on this machine"); -#else - return TRUE; -#endif - } - return FALSE; + VALUE execarg_obj, ret; + execarg_obj = rb_execarg_new(argc, argv, FALSE); + ret = pipe_open(execarg_obj, modestr, fmode, convconfig); + return ret; } static VALUE pipe_open_s(VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig) { + const char *cmd = RSTRING_PTR(prog); int argc = 1; VALUE *argv = &prog; - VALUE execarg_obj = Qnil; + VALUE execarg_obj, ret; - if (!is_popen_fork(prog)) - execarg_obj = rb_execarg_new(argc, argv, TRUE); - return pipe_open(execarg_obj, modestr, fmode, convconfig); + if (RSTRING_LEN(prog) == 1 && cmd[0] == '-') { +#if !defined(HAVE_FORK) + rb_raise(rb_eNotImpError, + "fork() function is unimplemented on this machine"); +#else + return pipe_open(Qnil, modestr, fmode, convconfig); +#endif + } + + execarg_obj = rb_execarg_new(argc, argv, TRUE); + ret = pipe_open(execarg_obj, modestr, fmode, convconfig); + return ret; } /* @@ -5805,7 +5810,7 @@ static VALUE rb_io_s_popen(int argc, VALUE *argv, VALUE klass) { const char *modestr; - VALUE pname, pmode, port, tmp, opt, execarg_obj; + VALUE pname, pmode, port, tmp, opt; int oflags, fmode; convconfig_t convconfig; @@ -5824,16 +5829,13 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass) #endif tmp = rb_ary_dup(tmp); RBASIC(tmp)->klass = 0; - execarg_obj = rb_execarg_new((int)len, RARRAY_PTR(tmp), TRUE); + port = pipe_open_v((int)len, RARRAY_PTR(tmp), modestr, fmode, &convconfig); rb_ary_clear(tmp); } else { SafeStringValue(pname); - execarg_obj = Qnil; - if (!is_popen_fork(pname)) - execarg_obj = rb_execarg_new(1, &pname, TRUE); + port = pipe_open_s(pname, modestr, fmode, &convconfig); } - port = pipe_open(execarg_obj, modestr, fmode, &convconfig); if (NIL_P(port)) { /* child */ if (rb_block_given_p()) { -- cgit v1.2.3