diff --git a/CHANGELOG.md b/CHANGELOG.md index bf93cfab..0c08f223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/spring/client/run.rb b/lib/spring/client/run.rb index 236af3de..3a60608a 100644 --- a/lib/spring/client/run.rb +++ b/lib/spring/client/run.rb @@ -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 @@ -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 }