diff --git a/lib/core/utils.rb b/lib/core/utils.rb index 5410bdd38c0fd9629e73f4b29e2f61915b0f0c75..cd5e659db5bf9e57b38f8ebd3f4ec670564bad91 100644 --- a/lib/core/utils.rb +++ b/lib/core/utils.rb @@ -24,6 +24,31 @@ module PML end end + def safe_system(*args) + # make sure spawned process get killed at exit + # hangs if subprocess refuses to terminate + pids = [] # holds the spawned pids + trap(0) do # kill spawned pid(s) when terminating + pids.each do |pid| + next unless pid + begin + Process.kill("TERM",pid) + $stderr.puts("Terminated spawned child with PID #{pid}") + rescue SystemCallError + # killed in the meantime + end + end + end + begin + pids.push(spawn(*args)) + rescue SystemCallError + return nil + end + Process.wait(pids.first) + trap(0, "DEFAULT") + $? == 0 + end + def internal_error(msg) raise Exception.new(format_msg("INTERNAL ERROR", msg)) end diff --git a/lib/tools/ait2pml.rb b/lib/tools/ait2pml.rb index b9885326248e36ba2a68746d28648be5552e0871..5639f40217616e3aa3f806b63e6c3d954c03f0db 100644 --- a/lib/tools/ait2pml.rb +++ b/lib/tools/ait2pml.rb @@ -24,8 +24,7 @@ class AitAnalyzeTool def AitAnalyzeTool.run(pml, options) needs_options(options, :a3, :apx_file) - system("#{options.a3} -b #{options.apx_file}") - unless $? == 0 + unless safe_system("#{options.a3} -b #{options.apx_file}") die "aiT (command: '#{options.a3}') failed batch processing #{options.apx_file} (exit status #{$?})" end end diff --git a/lib/tools/sweet.rb b/lib/tools/sweet.rb index e882b0de3f91bb87d7e40e897a001a02d8f8952c..d5799615c3b895cdfdade939e902d2dcaa996eb2 100644 --- a/lib/tools/sweet.rb +++ b/lib/tools/sweet.rb @@ -35,8 +35,9 @@ class AlfTool end cmd.push(options.bitcode_file) $stderr.puts("Executing #{cmd.join(" ")}") if options.verbose - system(*cmd) - die "#{options.alf_llc} failed with exit status #{$?}" unless $? == 0 + unless safe_system(*cmd) + die "#{options.alf_llc} failed with exit status #{$?}" + end end def AlfTool.default_ignored_definitions %w{__adddf3 __addsf3 __divdf3 __divsf3 __eqdf2} + diff --git a/platin b/platin index 5f13e4300199645f1d6eaad386f36ec7d96963b0..d7fc10d17a21872975ab343d2f90cde797cd2efc 100755 --- a/platin +++ b/platin @@ -102,4 +102,4 @@ elif [ "${COMMAND}" == "help" ] ; then exit 0 fi # Run command -${RUBY} -I ${LIBDIR} ${LIBDIR}/tools/"${COMMAND}".rb "${@}" +exec ${RUBY} -I ${LIBDIR} ${LIBDIR}/tools/"${COMMAND}".rb "${@}"