From 8e030bcd34da6296b1bda95f151c2ac4b777f617 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 25 Jun 2009 16:38:13 -0700 Subject: exec_cgi: small cleanups * avoid '' strings for GC-friendliness * Ensure the '' we do need is binary for 1.9 * Disable passing the raw rack.input object to the child process This is never possible with our new TeeInput wrapper. --- lib/unicorn/app/exec_cgi.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/unicorn/app') diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb index 8f81d78..4d8e701 100644 --- a/lib/unicorn/app/exec_cgi.rb +++ b/lib/unicorn/app/exec_cgi.rb @@ -42,11 +42,11 @@ module Unicorn::App # Calls the app def call(env) - out, err = Tempfile.new(''), Tempfile.new('') + out, err = Tempfile.new(nil), Tempfile.new(nil) out.unlink err.unlink inp = force_file_input(env) - inp.sync = out.sync = err.sync = true + out.sync = err.sync = true pid = fork { run_child(inp, out, err, env) } inp.close pid, status = Process.waitpid2(pid) @@ -121,17 +121,15 @@ module Unicorn::App # ensures rack.input is a file handle that we can redirect stdin to def force_file_input(env) inp = env['rack.input'] - if inp.respond_to?(:fileno) && Integer === inp.fileno - inp - elsif inp.size == 0 # inp could be a StringIO or StringIO-like object - ::File.open('/dev/null') + if inp.size == 0 # inp could be a StringIO or StringIO-like object + ::File.open('/dev/null', 'rb') else - tmp = Tempfile.new('') + tmp = Tempfile.new(nil) tmp.unlink tmp.binmode + tmp.sync = true - # Rack::Lint::InputWrapper doesn't allow sysread :( - buf = '' + buf = Z.dup while inp.read(CHUNK_SIZE, buf) tmp.syswrite(buf) end -- cgit v1.2.3-24-ge0c7