|
52 | 52 |
|
53 | 53 | require "#{TRUFFLERUBY_DIR}/lib/truffle/truffle/openssl-prefix.rb"
|
54 | 54 |
|
55 |
| -# wait for sub-processes to handle the interrupt |
56 |
| -trap(:INT) {} |
57 |
| - |
58 | 55 | MRI_TEST_MODULES = {
|
59 | 56 | '--no-sulong' => {
|
60 | 57 | help: 'exclude all tests requiring Sulong',
|
|
80 | 77 | }
|
81 | 78 | }
|
82 | 79 |
|
| 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 | + |
83 | 97 | module Utilities
|
84 | 98 | private
|
85 | 99 |
|
@@ -308,6 +322,13 @@ def raw_sh_with_timeout(timeout, pid)
|
308 | 322 | end
|
309 | 323 | end
|
310 | 324 |
|
| 325 | + def raw_sh_track_subprocess(pid) |
| 326 | + SUBPROCESSES << pid |
| 327 | + yield |
| 328 | + ensure |
| 329 | + SUBPROCESSES.delete(pid) |
| 330 | + end |
| 331 | + |
311 | 332 | def raw_sh(*args)
|
312 | 333 | options = args.last.is_a?(Hash) ? args.last : {}
|
313 | 334 | continue_on_failure = options.delete :continue_on_failure
|
@@ -335,14 +356,16 @@ def raw_sh(*args)
|
335 | 356 | rescue Errno::ENOENT # No such executable
|
336 | 357 | status = raw_sh_failed_status
|
337 | 358 | else
|
338 |
| - pipe_w.close if capture |
| 359 | + raw_sh_track_subprocess(pid) do |
| 360 | + pipe_w.close if capture |
339 | 361 |
|
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 |
346 | 369 | end
|
347 | 370 | end
|
348 | 371 |
|
@@ -1464,7 +1487,6 @@ def build_stats_native_runtime_compilable_methods(*args)
|
1464 | 1487 | end
|
1465 | 1488 |
|
1466 | 1489 | def metrics(command, *args)
|
1467 |
| - trap(:INT) { puts; exit } |
1468 | 1490 | args = args.dup
|
1469 | 1491 | case command
|
1470 | 1492 | when 'alloc'
|
|
0 commit comments