about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-12-08 17:33:51 +0000
committerEric Wong <e@80x24.org>2018-12-08 17:33:51 +0000
commit2ee9353fba7be5443db2ccdc3541586932ccf1f1 (patch)
treed3d39a754353c5078e468a219a289c2170d97614
parentdbadf731d06a79cdae7afd23f4c20fb8fbb9c07e (diff)
downloadyahns-2ee9353fba7be5443db2ccdc3541586932ccf1f1.tar.gz
Since we've required Ruby 2.0+ for a while, we can assume
descriptors are created with IO#close_on_exec=true and
avoid bloating our code with calls to it.
-rw-r--r--lib/yahns/config.rb2
-rw-r--r--lib/yahns/daemon.rb1
-rw-r--r--lib/yahns/queue_kqueue.rb6
-rw-r--r--lib/yahns/queue_quitter_pipe.rb1
-rw-r--r--lib/yahns/sigevent_pipe.rb1
-rw-r--r--lib/yahns/socket_helper.rb2
-rw-r--r--test/helper.rb2
-rw-r--r--test/server_helper.rb4
-rw-r--r--test/test_serve_static.rb1
-rw-r--r--test/test_server.rb3
-rw-r--r--test/test_unix_socket.rb4
-rw-r--r--test/test_wbuf.rb2
12 files changed, 6 insertions, 23 deletions
diff --git a/lib/yahns/config.rb b/lib/yahns/config.rb
index bcea0d4..e64cb77 100644
--- a/lib/yahns/config.rb
+++ b/lib/yahns/config.rb
@@ -409,7 +409,7 @@ class Yahns::Config # :nodoc:
     if String === val
       # we've already bound working_directory by the time we get here
       val = File.open(File.expand_path(val), "ab")
-      val.close_on_exec = val.sync = true
+      val.sync = true
     else
       rt = [ :puts, :write, :flush ] # match Rack::Lint
       rt.all? { |m| val.respond_to?(m) } or raise ArgumentError,
diff --git a/lib/yahns/daemon.rb b/lib/yahns/daemon.rb
index e3e2d9c..cca2f3a 100644
--- a/lib/yahns/daemon.rb
+++ b/lib/yahns/daemon.rb
@@ -32,7 +32,6 @@ module Yahns::Daemon # :nodoc:
       # We cannot use Yahns::Sigevent (eventfd) here because we need
       # to detect EOF on unexpected death, not just read/write
       rd, wr = IO.pipe
-      rd.close_on_exec = wr.close_on_exec = true
       grandparent = $$
       if fork
         wr.close # grandparent does not write
diff --git a/lib/yahns/queue_kqueue.rb b/lib/yahns/queue_kqueue.rb
index 064cd0e..3c4c51c 100644
--- a/lib/yahns/queue_kqueue.rb
+++ b/lib/yahns/queue_kqueue.rb
@@ -17,12 +17,6 @@ class Yahns::Queue < SleepyPenguin::Kqueue::IO # :nodoc:
 
   ADD_ONESHOT = Ev::ADD | Ev::ONESHOT # private
 
-  def self.new
-    rv = super
-    rv.close_on_exec = true
-    rv
-  end
-
   # for HTTP and HTTPS servers, we rely on the io writing to us, first
   # flags: QEV_RD/QEV_WR (usually QEV_RD)
   def queue_add(io, flags)
diff --git a/lib/yahns/queue_quitter_pipe.rb b/lib/yahns/queue_quitter_pipe.rb
index 789eacd..9a2e494 100644
--- a/lib/yahns/queue_quitter_pipe.rb
+++ b/lib/yahns/queue_quitter_pipe.rb
@@ -7,7 +7,6 @@ class Yahns::QueueQuitter # :nodoc:
   attr_reader :to_io
   def initialize
     @reader, @to_io = IO.pipe
-    @to_io.close_on_exec = true
   end
 
   def yahns_step
diff --git a/lib/yahns/sigevent_pipe.rb b/lib/yahns/sigevent_pipe.rb
index a85fb2a..f630e72 100644
--- a/lib/yahns/sigevent_pipe.rb
+++ b/lib/yahns/sigevent_pipe.rb
@@ -6,7 +6,6 @@ class Yahns::Sigevent # :nodoc:
   attr_reader :to_io
   def initialize
     @to_io, @wr = Kgio::Pipe.new
-    @to_io.close_on_exec = @wr.close_on_exec = true
   end
 
   def kgio_wait_readable(*args)
diff --git a/lib/yahns/socket_helper.rb b/lib/yahns/socket_helper.rb
index 9d4afc0..963c9fa 100644
--- a/lib/yahns/socket_helper.rb
+++ b/lib/yahns/socket_helper.rb
@@ -19,7 +19,7 @@ module Yahns::SocketHelper # :nodoc:
 
   def set_server_sockopt(sock, opt)
     opt = {backlog: 1024}.merge!(opt)
-    sock.close_on_exec = true
+    sock.close_on_exec = true # needed for inherited sockets
 
     TCPSocket === sock and sock.setsockopt(:IPPROTO_TCP, :TCP_NODELAY, 1)
     sock.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, 1)
diff --git a/test/helper.rb b/test/helper.rb
index 3023dee..550a0f1 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -125,7 +125,7 @@ class IO
 end if ! IO.method_defined?(:nread) && RUBY_PLATFORM =~ /linux/
 
 def cloexec_pipe
-  IO.pipe.each { |io| io.close_on_exec = true }
+  IO.pipe
 end
 
 def require_exec(cmd)
diff --git a/test/server_helper.rb b/test/server_helper.rb
index b794ee6..095cba1 100644
--- a/test/server_helper.rb
+++ b/test/server_helper.rb
@@ -52,9 +52,7 @@ module ServerHelper
   # only use for newly bound sockets
   def get_tcp_client(host, port, tries = 500)
     begin
-      c = TCPSocket.new(host, port)
-      c.close_on_exec = true
-      return c
+      return TCPSocket.new(host, port)
     rescue Errno::ECONNREFUSED
       raise if tries < 0
       tries -= 1
diff --git a/test/test_serve_static.rb b/test/test_serve_static.rb
index 68e84f7..837414b 100644
--- a/test/test_serve_static.rb
+++ b/test/test_serve_static.rb
@@ -38,7 +38,6 @@ class TestServeStatic < Testcase
 
     # ensure sendfile works on Unix sockets
     s = UNIXSocket.new(sock)
-    s.close_on_exec = true
     s.write "GET /COPYING\r\n\r\n"
     assert_equal gplv3, Timeout.timeout(30) { s.read }
     s.close
diff --git a/test/test_server.rb b/test/test_server.rb
index a113b43..75e1857 100644
--- a/test/test_server.rb
+++ b/test/test_server.rb
@@ -182,7 +182,6 @@ class TestServer < Testcase
     tmpdir = yahns_mktmpdir
     sock = "#{tmpdir}/sock"
     unix_srv = UNIXServer.new(sock)
-    unix_srv.close_on_exec = true
     msgs = %w(ZZ zz)
     err = @err
     cfg = Yahns::Config.new
@@ -234,7 +233,6 @@ class TestServer < Testcase
     bpipe[0].close
     a = UNIXSocket.new(sock)
     b = UNIXSocket.new(sock)
-    b.close_on_exec = a.close_on_exec = true
     a.write("GET /sleep HTTP/1.0\r\n\r\n")
     r = IO.select([a], nil, nil, 4)
     assert r, "nothing ready"
@@ -681,7 +679,6 @@ class TestServer < Testcase
     assert_equal "INFO HIHI\n", re.read
 
     c = UNIXSocket.new(sock)
-    c.close_on_exec = true
     c.write "GET /\r\n\r\n"
     assert_equal c, c.wait(30)
     assert_equal "OK", c.read
diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb
index 7b821e3..b4e338c 100644
--- a/test/test_unix_socket.rb
+++ b/test/test_unix_socket.rb
@@ -12,9 +12,7 @@ class TestUnixSocket < Testcase
   def unix_socket(path)
     Timeout.timeout(30) do
       begin
-        c = UNIXSocket.new(path)
-        c.close_on_exec = true
-        return c
+        return UNIXSocket.new(path)
       rescue Errno::ENOENT
         sleep 0.01
         retry
diff --git a/test/test_wbuf.rb b/test/test_wbuf.rb
index 89825db..0135958 100644
--- a/test/test_wbuf.rb
+++ b/test/test_wbuf.rb
@@ -19,7 +19,7 @@ class TestWbuf < Testcase
   end
 
   def socketpair
-    KgioUS.pair.each { |io| io.close_on_exec = true }
+    KgioUS.pair
   end
 
   def test_wbuf