Skip to content
This repository
Browse code

Fix signal handling behavior on Ruby 1.8.

  • Loading branch information...
commit 3b025e7115c8f9688e83df47937f53c5ed029e18 1 parent fe13b0b
Hongli Lai authored
16  lib/capybara/driver/webkit/browser.rb
@@ -118,7 +118,7 @@ def discover_server_port(read_pipe)
118 118
     end
119 119
 
120 120
     def forward_stdout(pipe)
121  
-      while !pipe.eof?
  121
+      while pipe_readable?(pipe)
122 122
         line = pipe.readline
123 123
         if @stdout
124 124
           @stdout.write(line)
@@ -128,6 +128,20 @@ def forward_stdout(pipe)
128 128
     rescue EOFError
129 129
     end
130 130
 
  131
+    if !defined?(RUBY_ENGINE) || (RUBY_ENGINE == "ruby" && RUBY_VERSION <= "1.8")
  132
+      # please note the use of IO::select() here, as it is used specifically to
  133
+      # preserve correct signal handling behavior in ruby 1.8.
  134
+      # https://github.com/thibaudgg/rb-fsevent/commit/d1a868bf8dc72dbca102bedbadff76c7e6c2dc21
  135
+      # https://github.com/thibaudgg/rb-fsevent/blob/1ca42b987596f350ee7b19d8f8210b7b6ae8766b/ext/fsevent/fsevent_watch.c#L171
  136
+      def pipe_readable?(pipe)
  137
+        IO.select([pipe])
  138
+      end
  139
+    else
  140
+      def pipe_readable?(pipe)
  141
+        !pipe.eof?
  142
+      end
  143
+    end
  144
+
131 145
     def connect
132 146
       Capybara.timeout(5) do
133 147
         attempt_connect
10  src/main.cpp
... ...
@@ -1,8 +1,18 @@
1 1
 #include "Server.h"
2 2
 #include <QtGui>
3 3
 #include <iostream>
  4
+#ifdef Q_OS_UNIX
  5
+  #include <unistd.h>
  6
+#endif
4 7
 
5 8
 int main(int argc, char **argv) {
  9
+#ifdef Q_OS_UNIX
  10
+  if (setpgid(0, 0) < 0) {
  11
+    std::cerr << "Unable to set new process group." << std::endl;
  12
+    return 1;
  13
+  }
  14
+#endif
  15
+
6 16
   QApplication app(argc, argv);
7 17
   app.setApplicationName("capybara-webkit");
8 18
   app.setOrganizationName("thoughtbot, inc");

0 notes on commit 3b025e7

Please sign in to comment.
Something went wrong with that request. Please try again.