Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created February 6, 2013 19:11
Show Gist options
  • Select an option

  • Save jonleighton/4724966 to your computer and use it in GitHub Desktop.

Select an option

Save jonleighton/4724966 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 b3ee0ac..b4dc85c 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..a79aecc 100644
--- a/lib/spring/commands.rb
+++ b/lib/spring/commands.rb
@@ -99,6 +99,8 @@ module Spring
end
def call(args)
+ # 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