Skip to content

Commit

Permalink
Use IO.popen to spawn webkit_server instead of fork and exec.
Browse files Browse the repository at this point in the history
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 thoughtbot#132.
  • Loading branch information
Trevor Smith committed Aug 19, 2011
1 parent dc49e5f commit d8abcbc
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/capybara/driver/webkit/browser.rb
Expand Up @@ -81,27 +81,23 @@ def render(path, width, height)
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)
Expand Down

0 comments on commit d8abcbc

Please sign in to comment.