From 068982973ac3a7bb15c2bfa61efd9530be968df1 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 03:41:08 +0300 Subject: [PATCH 1/2] Drain command output before waiting for the child --- lib/pkg-config.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pkg-config.rb b/lib/pkg-config.rb index 542d67c..7c45400 100644 --- a/lib/pkg-config.rb +++ b/lib/pkg-config.rb @@ -377,9 +377,10 @@ def run_command(*command_line) out: output, err: File::NULL) output.close + result = input.read _, status = Process.waitpid2(pid) return nil unless status.success? - input.read + result rescue SystemCallError nil end From 0c9ce635a1c7dbc095db340fafd61300357655b9 Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:18:45 +0300 Subject: [PATCH 2/2] Add regression coverage for drain command output before waiting for the child --- test/test-pkg-config.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test-pkg-config.rb b/test/test-pkg-config.rb index 67893b3..45e4f4d 100644 --- a/test/test-pkg-config.rb +++ b/test/test-pkg-config.rb @@ -1,5 +1,6 @@ require "mkmf" require "tempfile" +require "timeout" require "pkg-config" @@ -21,6 +22,18 @@ def setup @glib = PackageConfig.new("glib-2.0", options) end + def test_run_command_drains_output_before_waiting + output = Timeout.timeout(5) do + PackageConfig.__send__( + :run_command, + RbConfig.ruby, + "-e", + "STDOUT.write('x' * 131072)", + ) + end + assert_equal(131072, output.bytesize) + end + def only_pkg_config_version(major, minor) pkg_config_version = `#{@pkgconf} --version`.chomp current_major, current_minor = pkg_config_version.split(".").collect(&:to_i)