Skip to content

Commit

Permalink
Suspend and Resume on TSTP and CONT signals rails#361
Browse files Browse the repository at this point in the history
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal

as mentioned by @casper in Issue rails#361:
> the spring server is somehow attached to the PTY of the shell

the solution is to:
> trap SIGTSTP and tell the server to disengage from the PTY
> before the client process is suspended
  • Loading branch information
Kache committed Sep 12, 2018
1 parent c034d2d commit a9473e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fix binstubs not being replaced when their quoting style was changed (#534)
* Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true'
* Fix binstub failures when Bundler's `BUNDLE_APP_CONFIG` environment variable is present (#545)
* Properly suspend and resume on ctrl-z TSTP and CONT (#361)

## 2.0.2

Expand Down
14 changes: 14 additions & 0 deletions lib/spring/client/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def run_command(client, application)
if pid && !pid.empty?
log "got pid: #{pid}"

suspend_resume_on_tstp_cont(pid)

forward_signals(application)
status = application.read.to_i

Expand All @@ -181,6 +183,18 @@ def queue_signals
end
end

def suspend_resume_on_tstp_cont(pid)
trap("TSTP") {
log "suspended"
Process.kill("STOP", pid.to_i)
Process.kill("STOP", Process.pid)
}
trap("CONT") {
log "resumed"
Process.kill("CONT", pid.to_i)
}
end

def forward_signals(application)
@signal_queue.each { |sig| kill sig, application }

Expand Down

0 comments on commit a9473e9

Please sign in to comment.