From 44c23fe7b12c9c1a1aca59b9c727c2d01f001513 Mon Sep 17 00:00:00 2001 From: Oded Arbel Date: Tue, 22 Apr 2014 16:13:52 +0300 Subject: [PATCH] Prevent grandchild from crashing on exception execute_blocking's grandchild can have an exception thrown after cmd_err_write.close, in which case the rescue block will crash. --- lib/bluepill/system.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bluepill/system.rb b/lib/bluepill/system.rb index ccd2d51..09fbc48 100644 --- a/lib/bluepill/system.rb +++ b/lib/bluepill/system.rb @@ -181,8 +181,8 @@ def execute_blocking(cmd, options = {}) # finally, replace grandchild with cmd ::Kernel.exec(*Shellwords.shellwords(cmd)) rescue Exception => e - cmd_err_write.puts "Exception in grandchild: #{e.to_s}." - cmd_err_write.puts e.backtrace + (cmd_err_write.closed? ? STDERR : cmd_err_write).puts "Exception in grandchild: #{e.to_s}." + (cmd_err_write.closed? ? STDERR : cmd_err_write).puts e.backtrace exit 1 end }