From 5c28d02312677861cfcefd6128a2c0062b5980ca Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 20 Sep 2025 11:17:32 +0900 Subject: [PATCH] Avoid env command in facter plugin ... because it interferes with the capability of core facter utility to translate command to its full path. Also override of environment variables is not really necessary when 'mysqd' command is found in PATH. Signed-off-by: Takashi Kajinami --- lib/facter/mysqld_version.rb | 6 ++++-- spec/unit/facter/mysqld_version_spec.rb | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/facter/mysqld_version.rb b/lib/facter/mysqld_version.rb index 6a383190c..ad28fd5b8 100644 --- a/lib/facter/mysqld_version.rb +++ b/lib/facter/mysqld_version.rb @@ -2,8 +2,10 @@ Facter.add('mysqld_version') do setcode do - if Facter::Core::Execution.which('mysqld') || Facter::Core::Execution.which('/usr/libexec/mysqld') - Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') + if Facter::Core::Execution.which('mysqld') + Facter::Core::Execution.execute('mysqld --no-defaults -V 2>/dev/null') + elsif Facter::Core::Execution.which('/usr/libexec/mysqld') + Facter::Core::Execution.execute('/usr/libexec/mysqld --no-defaults -V 2>/dev/null') elsif Facter::Core::Execution.which('mariadbd') Facter::Core::Execution.execute('mariadbd --no-defaults -V 2>/dev/null') end diff --git a/spec/unit/facter/mysqld_version_spec.rb b/spec/unit/facter/mysqld_version_spec.rb index 6a029d1c2..b69cfd7ef 100644 --- a/spec/unit/facter/mysqld_version_spec.rb +++ b/spec/unit/facter/mysqld_version_spec.rb @@ -11,8 +11,23 @@ context 'with mysqld' do before :each do allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return('/usr/sbin/mysqld') + allow(Facter::Core::Execution).to receive(:which).with('/usr/libexec/mysqld').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return(false) + allow(Facter::Core::Execution).to receive(:execute).with('mysqld --no-defaults -V 2>/dev/null') + .and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') + end + + it { + expect(Facter.fact(:mysqld_version).value).to eq('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') + } + end + + context 'with mysqld in /usr/libexec/mysqld' do + before :each do + allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('/usr/libexec/mysqld').and_return('/usr/libexec/mysqld') allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return(false) - allow(Facter::Core::Execution).to receive(:execute).with('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') + allow(Facter::Core::Execution).to receive(:execute).with('/usr/libexec/mysqld --no-defaults -V 2>/dev/null') .and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') end