Skip to content

Instantly share code, notes, and snippets.

@rwjblue
Forked from jonleighton/foo.diff
Created February 6, 2013 19:36
Show Gist options
  • Save rwjblue/4725125 to your computer and use it in GitHub Desktop.
Save rwjblue/4725125 to your computer and use it in GitHub Desktop.
diff --git a/lib/spring/application.rb b/lib/spring/application.rb
index 6e241a8..69ef383 100644
--- a/lib/spring/application.rb
+++ b/lib/spring/application.rb
@@ -22,9 +22,6 @@ module Spring
@stdout = IO.new(STDOUT.fileno)
@stderr = IO.new(STDERR.fileno)
- @stdin = File.open('/dev/null', 'r')
-
- STDIN.reopen(@stdin)
end
def start
@@ -62,6 +59,7 @@ module Spring
def serve(client)
redirect_output(client) do
+ stdin = client.recv_io
args_length = client.gets.to_i
args = args_length.times.map { client.read(client.gets.to_i) }
command = Spring.command(args.shift)
@@ -72,6 +70,8 @@ module Spring
ActionDispatch::Reloader.prepare!
pid = fork {
+ Process.setsid
+ STDIN.reopen(stdin)
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
command.call(args)
}
@@ -103,13 +103,11 @@ module Spring
def redirect_output(socket)
STDOUT.reopen socket.recv_io
STDERR.reopen socket.recv_io
- STDIN.reopen socket.recv_io
yield
ensure
STDOUT.reopen @stdout
STDERR.reopen @stderr
- STDIN.reopen @stdin
end
end
end
diff --git a/lib/spring/client/run.rb b/lib/spring/client/run.rb
index 422a164..177b454 100644
--- a/lib/spring/client/run.rb
+++ b/lib/spring/client/run.rb
@@ -30,7 +30,7 @@ module Spring
application.send_io STDOUT
application.send_io STDERR
- application.send_io stdin_slave
+ application.send_io STDIN
application.puts args.length
diff --git a/lib/spring/commands.rb b/lib/spring/commands.rb
index 5527296..66f6380 100644
--- a/lib/spring/commands.rb
+++ b/lib/spring/commands.rb
@@ -94,11 +94,10 @@ module Spring
Spring.register_command "rake", Rake.new
class Console
- def setup
- require "rails/commands/console"
- end
-
def call(args)
+ require "rails/commands/console"
+ # irb does this when it's required, but STDOUT is different now
+ STDOUT.sync = true
ARGV.replace args
::Rails::Console.start(::Rails.application)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment