1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

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.
This commit is contained in:
Trevor Smith 2011-08-18 18:54:54 -06:00
parent dc49e5f875
commit d8abcbcb0f

View file

@ -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)