Skip to content

Commit

Permalink
Fix signal handling behavior on Ruby 1.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Aug 22, 2011
1 parent fe13b0b commit 3b025e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/capybara/driver/webkit/browser.rb
Expand Up @@ -118,7 +118,7 @@ def discover_server_port(read_pipe)
end

def forward_stdout(pipe)
while !pipe.eof?
while pipe_readable?(pipe)
line = pipe.readline
if @stdout
@stdout.write(line)
Expand All @@ -128,6 +128,20 @@ def forward_stdout(pipe)
rescue EOFError
end

if !defined?(RUBY_ENGINE) || (RUBY_ENGINE == "ruby" && RUBY_VERSION <= "1.8")
# please note the use of IO::select() here, as it is used specifically to
# preserve correct signal handling behavior in ruby 1.8.
# https://github.com/thibaudgg/rb-fsevent/commit/d1a868bf8dc72dbca102bedbadff76c7e6c2dc21
# https://github.com/thibaudgg/rb-fsevent/blob/1ca42b987596f350ee7b19d8f8210b7b6ae8766b/ext/fsevent/fsevent_watch.c#L171
def pipe_readable?(pipe)
IO.select([pipe])
end
else
def pipe_readable?(pipe)
!pipe.eof?
end
end

def connect
Capybara.timeout(5) do
attempt_connect
Expand Down
10 changes: 10 additions & 0 deletions src/main.cpp
@@ -1,8 +1,18 @@
#include "Server.h"
#include <QtGui>
#include <iostream>
#ifdef Q_OS_UNIX
#include <unistd.h>
#endif

int main(int argc, char **argv) {
#ifdef Q_OS_UNIX
if (setpgid(0, 0) < 0) {
std::cerr << "Unable to set new process group." << std::endl;
return 1;
}
#endif

QApplication app(argc, argv);
app.setApplicationName("capybara-webkit");
app.setOrganizationName("thoughtbot, inc");
Expand Down

0 comments on commit 3b025e7

Please sign in to comment.