about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-31 21:14:52 +0000
committerEric Wong <normalperson@yhbt.net>2009-10-31 14:22:14 -0700
commit9f707bc02ffba4e3b792aa7da325f9e550ea27c2 (patch)
tree7d394861887a067d72de9c1d80431e038c48cb58 /lib
parent2cb4226e52d5010eb4f92942e40499b6aa124262 (diff)
downloadunicorn-9f707bc02ffba4e3b792aa7da325f9e550ea27c2.tar.gz
`sh -c pwd` doesn't reliably read ENV["PWD"] on all platforms,
this means that directories that are symlinks may be ignored
and the real path is resolved.  This can be problematic when
doing upgrades for common deployment systems such as Capistrano
which rely on the working directory being a symlink.
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index ae1de59..de46c9e 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -92,9 +92,17 @@ module Unicorn
     #   Unicorn::HttpServer::START_CTX[0] = "/home/bofh/1.9.2/bin/unicorn"
     START_CTX = {
       :argv => ARGV.map { |arg| arg.dup },
-      # don't rely on Dir.pwd here since it's not symlink-aware, and
-      # symlink dirs are the default with Capistrano...
-      :cwd => `/bin/sh -c pwd`.chomp("\n"),
+      :cwd => lambda {
+          # favor ENV['PWD'] since it is (usually) symlink aware for
+          # Capistrano and like systems
+          begin
+            a = File.stat(pwd = ENV['PWD'])
+            b = File.stat(Dir.pwd)
+            a.ino == b.ino && a.dev == b.dev ? pwd : Dir.pwd
+          rescue
+            Dir.pwd
+          end
+        }.call,
       0 => $0.dup,
     }