remove-shell-invocation-optimization.patch

Akira Tanaka, 06/04/2012 10:34 PM

Download (5.07 KB)

View differences:

process.c (working copy)
1793 1793
    e->prog = prog ? RSTRING_PTR(prog) : 0;
1794 1794
    e->progname = prog;
1795 1795

  
1796
#ifndef _WIN32
1797
    if (e->use_shell) {
1798
        char *p;
1799
        int has_meta = 0;
1800
        int has_nonspace = 0;
1801
        for (p = RSTRING_PTR(prog); *p; p++) {
1802
            if (*p != ' ' && *p != '\t')
1803
                has_nonspace = 1;
1804
            if (strchr("*?{}[]<>()~&|\\$;'`\"\n", *p))
1805
                has_meta = 1;
1806
        }
1807
        if (has_nonspace && !has_meta) {
1808
            /* avoid shell since no shell meta charactor found. */
1809
            e->use_shell = 0;
1810
        }
1811
        if (!e->use_shell) {
1812
            VALUE argv_buf;
1813
            argv_buf = hide_obj(rb_str_buf_new(0));
1814
            p = RSTRING_PTR(prog);
1815
            while (*p) {
1816
                while (*p == ' ' || *p == '\t')
1817
                    p++;
1818
                if (*p) {
1819
                    char *w = p;
1820
                    while (*p && *p != ' ' && *p != '\t')
1821
                        p++;
1822
                    rb_str_buf_cat(argv_buf, w, p-w);
1823
                    rb_str_buf_cat(argv_buf, "", 1); /* append '\0' */
1824
                }
1825
            }
1826
            e->argv_buf = argv_buf;
1827
            e->progname = hide_obj(rb_str_new_cstr(RSTRING_PTR(argv_buf)));
1828
            e->prog = RSTRING_PTR(e->progname);
1829
        }
1830
    }
1831
#endif
1832

  
1833 1796
    if (!e->use_shell && !e->argv_buf) {
1834 1797
        int i;
1835 1798
        VALUE argv_buf;
test/ruby/test_io.rb (working copy)
1173 1173
    assert_equal(nil, r.pid)
1174 1174
    assert_equal(nil, w.pid)
1175 1175

  
1176
    pipe = IO.popen(EnvUtil.rubybin, "r+")
1176
    pipe = IO.popen([['ruby', EnvUtil.rubybin]], "r+")
1177 1177
    pid1 = pipe.pid
1178 1178
    pipe.puts "p $$"
1179 1179
    pipe.close_write
test/ruby/test_process.rb (working copy)
250 250

  
251 251
    with_tmpchdir {|d|
252 252
      prog = "#{d}/notexist"
253
      e = assert_raise(Errno::ENOENT) {
254
        Process.wait Process.spawn({"FOO"=>"BAR"}, prog)
253
      assert_nothing_raised {
254
        Process.wait Process.spawn({"FOO"=>"BAR"}, prog,
255
          :err => 'shell-error')
255 256
      }
256
      assert_equal(prog, e.message.sub(/.* - /, ''))
257
      assert_not_equal('', File.read('shell-error'))
257 258
      e = assert_raise(Errno::ENOENT) {
258 259
        Process.wait Process.spawn({"FOO"=>"BAR"}, [prog, "blar"])
259 260
      }
......
471 472

  
472 473
      unless windows?
473 474
        # passing non-stdio fds is not supported on Windows
474
        assert_raise(Errno::ENOENT) {
475
          Process.wait Process.spawn("non-existing-command", (3..60).to_a=>["err", File::WRONLY|File::CREAT])
475
        assert_nothing_raised {
476
          Process.wait Process.spawn("non-existing-command",
477
            :err => 'shell-error',
478
            (3..60).to_a=>["err", File::WRONLY|File::CREAT])
476 479
        }
480
        assert_not_equal("", File.read("shell-error"))
477 481
        assert_equal("", File.read("err"))
478 482
      end
479 483

  
......
824 828
        File.open("result", "w") {|t| t << "haha pid=#{$$} ppid=#{Process.ppid}" }
825 829
        exit 5
826 830
      End
827
      str = "#{RUBY} script"
831
      str = "exec #{RUBY} script"
828 832
      ret = system(str)
829 833
      status = $?
830 834
      assert_equal(false, ret)
......
840 844
        File.open("result", "w") {|t| t << "hihi pid=#{$$} ppid=#{Process.ppid}" }
841 845
        exit 6
842 846
      End
843
      str = "#{RUBY} script"
847
      str = "exec #{RUBY} script"
844 848
      pid = spawn(str)
845 849
      Process.wait pid
846 850
      status = $?
......
857 861
        print "fufu pid=#{$$} ppid=#{Process.ppid}"
858 862
        exit 7
859 863
      End
860
      str = "#{RUBY} script"
864
      str = "exec #{RUBY} script"
861 865
      io = IO.popen(str)
862 866
      pid = io.pid
863 867
      result = io.read
......
884 888
      End
885 889
      write_file("s", <<-"End")
886 890
	ruby = #{RUBY.dump}
887
	exec "\#{ruby} script"
891
	exec ruby, "script"
888 892
      End
889 893
      pid = spawn(RUBY, "s")
890 894
      Process.wait pid
test/test_pty.rb (working copy)
155 155
    bug3672 = '[ruby-dev:41965]'
156 156
    Dir.mktmpdir do |tmpdir|
157 157
      assert_raise(Errno::ENOENT, bug3672) {
158
        command = File.join(tmpdir, "no-such-command")
158 159
        begin
159
          PTY.getpty(File.join(tmpdir, "no-such-command"))
160
          PTY.getpty(command, 'arg')
160 161
        rescue RuntimeError
161 162
          skip $!
162 163
        end