about summary refs log tree commit homepage
path: root/lib/unicorn/app/exec_cgi.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-07-19 17:11:01 -0700
committerEric Wong <normalperson@yhbt.net>2009-07-19 17:12:40 -0700
commit86fd8957c7799368619aa8ce054b440716494a11 (patch)
treeb2f3c516424cf471a259d953f9b722e4ff19290a /lib/unicorn/app/exec_cgi.rb
parentf3d7ea324c893ba9d8787afbaa9d2e55fcae0133 (diff)
downloadunicorn-86fd8957c7799368619aa8ce054b440716494a11.tar.gz
With the 1.9.2preview1 release (and presumably 1.9.1 p243), the
Ruby core team has decided that bending over backwards to
support crippled operating/file systems was necessary and that
files must be closed before unlinking.

Regardless, this is more efficient than using Tempfile because:

  1) no delegation is necessary, this is a real File object

  2) no mkdir is necessary for locking, we can trust O_EXCL
     to work properly without unnecessary FS activity

  3) no finalizer is needed to unlink the file, we unlink
     it as soon as possible after creation.

(cherry picked from commit 344b85ff28e160daa6563ab7c80b733abdeb874a)

Conflicts:

	lib/unicorn.rb
	lib/unicorn/app/exec_cgi.rb
	lib/unicorn/tee_input.rb
Diffstat (limited to 'lib/unicorn/app/exec_cgi.rb')
-rw-r--r--lib/unicorn/app/exec_cgi.rb9
1 files changed, 2 insertions, 7 deletions
diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb
index 8f81d78..b0fbedc 100644
--- a/lib/unicorn/app/exec_cgi.rb
+++ b/lib/unicorn/app/exec_cgi.rb
@@ -42,11 +42,8 @@ module Unicorn::App
 
     # Calls the app
     def call(env)
-      out, err = Tempfile.new(''), Tempfile.new('')
-      out.unlink
-      err.unlink
+      out, err = Unicorn::Util.tmpio, Unicorn::Util.tmpio
       inp = force_file_input(env)
-      inp.sync = out.sync = err.sync = true
       pid = fork { run_child(inp, out, err, env) }
       inp.close
       pid, status = Process.waitpid2(pid)
@@ -126,9 +123,7 @@ module Unicorn::App
       elsif inp.size == 0 # inp could be a StringIO or StringIO-like object
         ::File.open('/dev/null')
       else
-        tmp = Tempfile.new('')
-        tmp.unlink
-        tmp.binmode
+        tmp = Unicorn::Util.tmpio
 
         # Rack::Lint::InputWrapper doesn't allow sysread :(
         buf = ''