Skip to content

Commit

Permalink
Add a patch for RubyInstaller to avoid crash on start up
Browse files Browse the repository at this point in the history
When a non-ASCII key exists under the registry key
`SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/`, Fluentd fails to
start workers due to `Encoding::UndefinedConversionError`.
This patch avoid this issue.

Fix #616

Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed Feb 16, 2024
1 parent 7e637b3 commit ff55475
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
15 changes: 12 additions & 3 deletions fluent-package/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ class BuildTask
desc "Install Ruby for Windows"
task :rubyinstaller => [:"download:ruby"] do
extract_ruby_installer
apply_ruby_installer_patches
setup_windows_build_env
find_and_put_dynamiclibs
apply_ruby_installer_patches
end

desc "Install ruby gems"
Expand Down Expand Up @@ -791,8 +791,17 @@ class BuildTask
dependency = Gem::Dependency.new('', version_condition)
if dependency.match?('', ruby_version)
patch_path = File.join(__dir__, "patches", patch_name)
cd(ruby_lib_dir) do
sh("ridk", "exec", "patch", "-p2", "--input=#{patch_path}")
if patch_name.start_with?("rubyinstaller/")
# Patches for RubyInstaller's binary package
base_dir = fluent_package_staging_dir
strip_level = 1
else
# patches for Ruby source tree
base_dir = ruby_lib_dir
strip_level = 2
end
cd(base_dir) do
sh("ridk", "exec", "patch", "-p#{strip_level}", "--input=#{patch_path}")
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions fluent-package/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
BUNDLED_RUBY_INSTALLER_X64_VERSION = "3.2.2-1"
BUNDLED_RUBY_INSTALLER_X64_SHA256SUM = "1f0f55ba0790676be6d701515a244159e9ca2d6314f1101560e3e8a277a2661e"

# Patch files are assumed to be for Ruby's source tree, then applied to
# lib/ruby/x.y.0 in RubyInstaller. So that "-p2" options will be passed
# to patch command.
# Files under rubyinstaller/ are patches for RubyInstaller's binary package.
# Other patches for Ruby's source tree which can be shared with BUNDLED_RUBY_PATCHES.
BUNDLED_RUBY_INSTALLER_PATCHES = [
# An example entry:
# ["ruby-3.0/0001-ruby-resolv-Fix-confusion-of-received-response-messa.patch", ["= 3.0.1"]],
["rubyinstaller/0001-Skip-searching-registry-for-detecting-MSYS2-installa.patch", [">= 0"]],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 8616bc218e6461f977c78d1a8028a7c4ab2b4ece Mon Sep 17 00:00:00 2001
From: Takuro Ashie <[email protected]>
Date: Fri, 16 Feb 2024 13:50:04 +0900
Subject: [PATCH] Skip searching registry for detecting MSYS2 installation

It causes crash when the registry key contains a non-ASCII subkey and
ruby is executed with '-Eascii-8bit:ascii-8bit'.
In addition, make sure to eliminate influences of external MSYS2.

Signed-off-by: Takuro Ashie <[email protected]>
---
.../3.2.0/ruby_installer/runtime/msys2_installation.rb | 2 ++
1 file changed, 2 insertions(+)

diff --git a/lib/ruby/site_ruby/3.2.0/ruby_installer/runtime/msys2_installation.rb b/lib/ruby/site_ruby/3.2.0/ruby_installer/runtime/msys2_installation.rb
index ae1db823..062d10bf 100644
--- a/lib/ruby/site_ruby/3.2.0/ruby_installer/runtime/msys2_installation.rb
+++ b/lib/ruby/site_ruby/3.2.0/ruby_installer/runtime/msys2_installation.rb
@@ -62,6 +62,7 @@ module Runtime # Rewrite from D:/a/rubyinstaller2/rubyinstaller2/lib/ruby_instal
yield "c:/msys64"
yield "c:/msys32"

+=begin
# If msys2 is installed per installer.exe
require "win32/registry"
[
@@ -86,6 +87,7 @@ module Runtime # Rewrite from D:/a/rubyinstaller2/rubyinstaller2/lib/ruby_instal
rescue Win32::Registry::Error
end
end
+=end

ENV['PATH'] && ENV['PATH'].split(";").each do |path|
# If /path/to/msys64 is in the PATH (e.g. Chocolatey)
--
2.34.1

0 comments on commit ff55475

Please sign in to comment.