summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-25 16:38:13 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-25 16:56:27 -0700
commit8e030bcd34da6296b1bda95f151c2ac4b777f617 (patch)
treef3a5707c9880e52f106ed00c7a6e90c43b472626
parent1574d8ce531d79fc905be2f319fa703fb0710e96 (diff)
* 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.
-rw-r--r--lib/unicorn/app/exec_cgi.rb16
1 files changed, 7 insertions, 9 deletions
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