From d8abcbcb0f935d1446c9c41b734dded9e940219b Mon Sep 17 00:00:00 2001 From: Trevor Smith Date: Thu, 18 Aug 2011 18:54:54 -0600 Subject: [PATCH] Use IO.popen to spawn webkit_server instead of fork and exec. This makes capybara-webkit compatible with DRb (which replaces $stdout with an object that does not support #reopen). Also, by default, popen closes all nonstandard file descriptors in the spawned process, fixing problems related to #132. --- lib/capybara/driver/webkit/browser.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/capybara/driver/webkit/browser.rb b/lib/capybara/driver/webkit/browser.rb index f753100..634d8ff 100644 --- a/lib/capybara/driver/webkit/browser.rb +++ b/lib/capybara/driver/webkit/browser.rb @@ -81,27 +81,23 @@ class Capybara::Driver::Webkit private def start_server - read_pipe, write_pipe = fork_server - @server_port = discover_server_port(read_pipe) + pipe = fork_server + @server_port = discover_server_port(pipe) @stdout_thread = Thread.new do Thread.current.abort_on_exception = true - forward_stdout(read_pipe) + forward_stdout(pipe) end end def fork_server server_path = File.expand_path("../../../../../bin/webkit_server", __FILE__) - read_pipe, write_pipe = IO.pipe - @pid = fork do - $stdout.reopen write_pipe - read_pipe.close - exec(server_path) - end + pipe = IO.popen(server_path) + @pid = pipe.pid + at_exit { Process.kill("INT", @pid) } - write_pipe.close - [read_pipe, write_pipe] + pipe end def discover_server_port(read_pipe)