Permalink
Browse files

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.
  • Loading branch information...
1 parent dc49e5f commit d8abcbcb0f935d1446c9c41b734dded9e940219b @trevorsmith trevorsmith committed Aug 19, 2011
Showing with 7 additions and 11 deletions.
  1. +7 −11 lib/capybara/driver/webkit/browser.rb
View
18 lib/capybara/driver/webkit/browser.rb
@@ -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)

0 comments on commit d8abcbc

Please sign in to comment.