* [PATCH] remove IO#close_on_exec= calls
@ 2018-12-08 17:35 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2018-12-08 17:35 UTC (permalink / raw)
To: yahns-public
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.
---
lib/yahns/config.rb | 2 +-
lib/yahns/daemon.rb | 1 -
lib/yahns/queue_kqueue.rb | 6 ------
lib/yahns/queue_quitter_pipe.rb | 1 -
lib/yahns/sigevent_pipe.rb | 1 -
lib/yahns/socket_helper.rb | 2 +-
test/helper.rb | 2 +-
test/server_helper.rb | 4 +---
test/test_serve_static.rb | 1 -
test/test_server.rb | 3 ---
test/test_unix_socket.rb | 4 +---
test/test_wbuf.rb | 2 +-
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 @@ def errors(val)
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 @@ def self.daemon(yahns_server)
# 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 @@ def so_reuseport
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 @@ def nread
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 @@ def quit_wait(pid)
# 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 @@ def test_serve_static
# 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 @@ def test_check_client_connection
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 @@ def a.each
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 @@ def test_errors
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 @@ def self.output_buffer_tmpdir
end
def socketpair
- KgioUS.pair.each { |io| io.close_on_exec = true }
+ KgioUS.pair
end
def test_wbuf
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-12-08 17:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-08 17:35 [PATCH] remove IO#close_on_exec= calls Eric Wong
Code repositories for project(s) associated with this public inbox
http://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).