Skip to content

Commit 9af6822

Browse files
committed
JT: Forward signals to sub-processes, so they get notified when sending a signal to jt
1 parent cd0890d commit 9af6822

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

tool/jt.rb

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252

5353
require "#{TRUFFLERUBY_DIR}/lib/truffle/truffle/openssl-prefix.rb"
5454

55-
# wait for sub-processes to handle the interrupt
56-
trap(:INT) {}
57-
5855
MRI_TEST_MODULES = {
5956
'--no-sulong' => {
6057
help: 'exclude all tests requiring Sulong',
@@ -80,6 +77,23 @@
8077
}
8178
}
8279

80+
SUBPROCESSES = []
81+
82+
# Forward signals to sub-processes, so they get notified when sending a signal to jt
83+
[:SIGINT, :SIGTERM].each do |signal|
84+
trap(signal) do
85+
SUBPROCESSES.each do |pid|
86+
puts "\nSending #{signal} to process #{pid}"
87+
begin
88+
Process.kill(signal, pid)
89+
rescue Errno::ESRCH
90+
# Already killed
91+
end
92+
end
93+
# Keep running jt which will wait for the subprocesses termination
94+
end
95+
end
96+
8397
module Utilities
8498
private
8599

@@ -308,6 +322,13 @@ def raw_sh_with_timeout(timeout, pid)
308322
end
309323
end
310324

325+
def raw_sh_track_subprocess(pid)
326+
SUBPROCESSES << pid
327+
yield
328+
ensure
329+
SUBPROCESSES.delete(pid)
330+
end
331+
311332
def raw_sh(*args)
312333
options = args.last.is_a?(Hash) ? args.last : {}
313334
continue_on_failure = options.delete :continue_on_failure
@@ -335,14 +356,16 @@ def raw_sh(*args)
335356
rescue Errno::ENOENT # No such executable
336357
status = raw_sh_failed_status
337358
else
338-
pipe_w.close if capture
359+
raw_sh_track_subprocess(pid) do
360+
pipe_w.close if capture
339361

340-
result = raw_sh_with_timeout(timeout, pid) do
341-
out = pipe_r.read if capture
342-
_, status = Process.waitpid2(pid)
343-
end
344-
if result == :timeout
345-
status = raw_sh_failed_status
362+
result = raw_sh_with_timeout(timeout, pid) do
363+
out = pipe_r.read if capture
364+
_, status = Process.waitpid2(pid)
365+
end
366+
if result == :timeout
367+
status = raw_sh_failed_status
368+
end
346369
end
347370
end
348371

@@ -1464,7 +1487,6 @@ def build_stats_native_runtime_compilable_methods(*args)
14641487
end
14651488

14661489
def metrics(command, *args)
1467-
trap(:INT) { puts; exit }
14681490
args = args.dup
14691491
case command
14701492
when 'alloc'

0 commit comments

Comments
 (0)