From a9473e925e91b9d5844e10efdbb02a8c858aaed1 Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Thu, 16 Feb 2017 14:34:43 -0800 Subject: [PATCH] Suspend and Resume on TSTP and CONT signals #361 ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal as mentioned by @casper in Issue #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 --- CHANGELOG.md | 1 + lib/spring/client/run.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) 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 }