Skip to content

Commit

Permalink
Merge pull request #514 from Kache/suspend-resume-on-tstp-cont
Browse files Browse the repository at this point in the history
Suspend and Resume on TSTP and CONT signals #361
  • Loading branch information
jeremy authored Nov 19, 2018
2 parents bd91b03 + a9473e9 commit 309ec0d
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 309ec0d

Please sign in to comment.