From 5ab907f2fa3bbbd53eb8fa473e4ceb5f65be303f Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Tue, 23 Jul 2024 18:48:42 +0100 Subject: [PATCH] system_command: fix EBADF on Ctrl+C --- Library/Homebrew/system_command.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index 94ae4444ce..432043df01 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -265,15 +265,16 @@ class SystemCommand raise Timeout::Error if raw_wait_thr.join(Utils::Timer.remaining(end_time)).nil? @status = raw_wait_thr.value - - thread_ready_queue.pop - line_thread.raise ProcessTerminatedInterrupt.new - thread_done_queue << true - line_thread.join rescue Interrupt Process.kill("INT", raw_wait_thr.pid) if raw_wait_thr && !sudo? raise Interrupt ensure + if line_thread + thread_ready_queue.pop + line_thread.raise ProcessTerminatedInterrupt.new + thread_done_queue << true + line_thread.join + end raw_stdin&.close raw_stdout&.close raw_stderr&.close