diff options
-rw-r--r-- | lib/unicorn.rb | 4 | ||||
-rw-r--r-- | lib/unicorn/socket.rb | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 9c6aab7..02bf20a 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -265,9 +265,7 @@ module Unicorn %w(USR1 USR2 HUP).each { |sig| trap(sig, 'IGNORE') } @after_fork.call(self, worker_nr) if @after_fork - if defined?(Fcntl::FD_CLOEXEC) - @listeners.each { |s| s.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } - end + @listeners.each { |sock| set_cloexec(sock) } nr_before = nr = 0 client = nil alive = true diff --git a/lib/unicorn/socket.rb b/lib/unicorn/socket.rb index bc09688..cba921f 100644 --- a/lib/unicorn/socket.rb +++ b/lib/unicorn/socket.rb @@ -48,6 +48,10 @@ module Unicorn sock.setsockopt(SOL_TCP, TCP_CORK, 1) if defined?(TCP_CORK) end + def set_cloexec(io) + io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined?(Fcntl::FD_CLOEXEC) + end + def set_server_sockopt(sock) if defined?(TCP_DEFER_ACCEPT) sock.setsockopt(SOL_TCP, TCP_DEFER_ACCEPT, 1) rescue nil |