diff options
author | Eric Wong <e@80x24.org> | 2015-02-05 17:31:42 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-02-05 17:34:37 +0000 |
commit | baab2fc0600c284bf5108a9d9b02b774174ded5d (patch) | |
tree | e57c8d7ea599960b06666469a40283e01200754e /lib/unicorn | |
parent | 682c9ffa365a2cf5439845be6e0e693d352cfe94 (diff) | |
download | unicorn-baab2fc0600c284bf5108a9d9b02b774174ded5d.tar.gz |
IO#close_on_exec* methods are available since Ruby 1.9.1. It allows us to use less bytecode as it requires fewer operands and avoids constant lookups.
Diffstat (limited to 'lib/unicorn')
-rw-r--r-- | lib/unicorn/http_server.rb | 9 | ||||
-rw-r--r-- | lib/unicorn/util.rb | 1 |
2 files changed, 4 insertions, 6 deletions
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index 8a295f0..95a8ffe 100644 --- a/lib/unicorn/http_server.rb +++ b/lib/unicorn/http_server.rb @@ -434,10 +434,7 @@ class Unicorn::HttpServer self.reexec_pid = fork do listener_fds = {} LISTENERS.each do |sock| - # IO#close_on_exec= will be available on any future version of - # Ruby that sets FD_CLOEXEC by default on new file descriptors - # ref: http://redmine.ruby-lang.org/issues/5041 - sock.close_on_exec = false if sock.respond_to?(:close_on_exec=) + sock.close_on_exec = false listener_fds[sock.fileno] = sock end ENV['UNICORN_FD'] = listener_fds.keys.join(',') @@ -451,7 +448,7 @@ class Unicorn::HttpServer next if listener_fds.include?(io) io = IO.for_fd(io) rescue next io.autoclose = false - io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + io.close_on_exec = true end # exec(command, hash) works in at least 1.9.1+, but will only be @@ -607,7 +604,7 @@ class Unicorn::HttpServer WORKERS.clear after_fork.call(self, worker) # can drop perms and create listeners - LISTENERS.each { |sock| sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) } + LISTENERS.each { |sock| sock.close_on_exec = true } worker.user(*user) if user.kind_of?(Array) && ! worker.switched self.timeout /= 2.0 # halve it for select() diff --git a/lib/unicorn/util.rb b/lib/unicorn/util.rb index 94c4e37..c7784bd 100644 --- a/lib/unicorn/util.rb +++ b/lib/unicorn/util.rb @@ -1,5 +1,6 @@ # -*- encoding: binary -*- +require 'fcntl' module Unicorn::Util # :stopdoc: |