Feature #2715 ยป remove-shell-invocation-optimization.patch
process.c (working copy) | ||
---|---|---|
e->prog = prog ? RSTRING_PTR(prog) : 0;
|
||
e->progname = prog;
|
||
#ifndef _WIN32
|
||
if (e->use_shell) {
|
||
char *p;
|
||
int has_meta = 0;
|
||
int has_nonspace = 0;
|
||
for (p = RSTRING_PTR(prog); *p; p++) {
|
||
if (*p != ' ' && *p != '\t')
|
||
has_nonspace = 1;
|
||
if (strchr("*?{}[]<>()~&|\\$;'`\"\n", *p))
|
||
has_meta = 1;
|
||
}
|
||
if (has_nonspace && !has_meta) {
|
||
/* avoid shell since no shell meta charactor found. */
|
||
e->use_shell = 0;
|
||
}
|
||
if (!e->use_shell) {
|
||
VALUE argv_buf;
|
||
argv_buf = hide_obj(rb_str_buf_new(0));
|
||
p = RSTRING_PTR(prog);
|
||
while (*p) {
|
||
while (*p == ' ' || *p == '\t')
|
||
p++;
|
||
if (*p) {
|
||
char *w = p;
|
||
while (*p && *p != ' ' && *p != '\t')
|
||
p++;
|
||
rb_str_buf_cat(argv_buf, w, p-w);
|
||
rb_str_buf_cat(argv_buf, "", 1); /* append '\0' */
|
||
}
|
||
}
|
||
e->argv_buf = argv_buf;
|
||
e->progname = hide_obj(rb_str_new_cstr(RSTRING_PTR(argv_buf)));
|
||
e->prog = RSTRING_PTR(e->progname);
|
||
}
|
||
}
|
||
#endif
|
||
if (!e->use_shell && !e->argv_buf) {
|
||
int i;
|
||
VALUE argv_buf;
|
test/ruby/test_io.rb (working copy) | ||
---|---|---|
assert_equal(nil, r.pid)
|
||
assert_equal(nil, w.pid)
|
||
pipe = IO.popen(EnvUtil.rubybin, "r+")
|
||
pipe = IO.popen([['ruby', EnvUtil.rubybin]], "r+")
|
||
pid1 = pipe.pid
|
||
pipe.puts "p $$"
|
||
pipe.close_write
|
test/ruby/test_process.rb (working copy) | ||
---|---|---|
with_tmpchdir {|d|
|
||
prog = "#{d}/notexist"
|
||
e = assert_raise(Errno::ENOENT) {
|
||
Process.wait Process.spawn({"FOO"=>"BAR"}, prog)
|
||
assert_nothing_raised {
|
||
Process.wait Process.spawn({"FOO"=>"BAR"}, prog,
|
||
:err => 'shell-error')
|
||
}
|
||
assert_equal(prog, e.message.sub(/.* - /, ''))
|
||
assert_not_equal('', File.read('shell-error'))
|
||
e = assert_raise(Errno::ENOENT) {
|
||
Process.wait Process.spawn({"FOO"=>"BAR"}, [prog, "blar"])
|
||
}
|
||
... | ... | |
unless windows?
|
||
# passing non-stdio fds is not supported on Windows
|
||
assert_raise(Errno::ENOENT) {
|
||
Process.wait Process.spawn("non-existing-command", (3..60).to_a=>["err", File::WRONLY|File::CREAT])
|
||
assert_nothing_raised {
|
||
Process.wait Process.spawn("non-existing-command",
|
||
:err => 'shell-error',
|
||
(3..60).to_a=>["err", File::WRONLY|File::CREAT])
|
||
}
|
||
assert_not_equal("", File.read("shell-error"))
|
||
assert_equal("", File.read("err"))
|
||
end
|
||
... | ... | |
File.open("result", "w") {|t| t << "haha pid=#{$$} ppid=#{Process.ppid}" }
|
||
exit 5
|
||
End
|
||
str = "#{RUBY} script"
|
||
str = "exec #{RUBY} script"
|
||
ret = system(str)
|
||
status = $?
|
||
assert_equal(false, ret)
|
||
... | ... | |
File.open("result", "w") {|t| t << "hihi pid=#{$$} ppid=#{Process.ppid}" }
|
||
exit 6
|
||
End
|
||
str = "#{RUBY} script"
|
||
str = "exec #{RUBY} script"
|
||
pid = spawn(str)
|
||
Process.wait pid
|
||
status = $?
|
||
... | ... | |
print "fufu pid=#{$$} ppid=#{Process.ppid}"
|
||
exit 7
|
||
End
|
||
str = "#{RUBY} script"
|
||
str = "exec #{RUBY} script"
|
||
io = IO.popen(str)
|
||
pid = io.pid
|
||
result = io.read
|
||
... | ... | |
End
|
||
write_file("s", <<-"End")
|
||
ruby = #{RUBY.dump}
|
||
exec "\#{ruby} script"
|
||
exec ruby, "script"
|
||
End
|
||
pid = spawn(RUBY, "s")
|
||
Process.wait pid
|
test/test_pty.rb (working copy) | ||
---|---|---|
bug3672 = '[ruby-dev:41965]'
|
||
Dir.mktmpdir do |tmpdir|
|
||
assert_raise(Errno::ENOENT, bug3672) {
|
||
command = File.join(tmpdir, "no-such-command")
|
||
begin
|
||
PTY.getpty(File.join(tmpdir, "no-such-command"))
|
||
PTY.getpty(command, 'arg')
|
||
rescue RuntimeError
|
||
skip $!
|
||
end
|