From 4dc7185699180e4c05fd35db6660ed2f409b5b56 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 4 Jul 2023 11:26:48 +0200 Subject: [PATCH 1/2] Avoid downcasing facts in service provider If the operatingsystem or osfamily fact is missing this will result in nil.downcase. In practice that's unlikely, but in some test scenarios it can happen. By using the properly cased values it removes the need to downcase, which is also slightly faster. --- lib/puppet/provider/service/init.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 02c220bb192..db46436a0cf 100644 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -21,9 +21,9 @@ def self.defpath # Debian and Ubuntu should use the Debian provider. # RedHat systems should use the RedHat provider. confine :true => begin - os = Puppet.runtime[:facter].value(:operatingsystem).downcase - family = Puppet.runtime[:facter].value(:osfamily).downcase - !(os == 'debian' || os == 'ubuntu' || family == 'redhat') + os = Puppet.runtime[:facter].value(:operatingsystem) + family = Puppet.runtime[:facter].value(:osfamily) + !(os == 'Debian' || os == 'Ubuntu' || family == 'RedHat') end # We can't confine this here, because the init path can be overridden. From d231c6054df9100fd521dd486a62b38926f56d0a Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 7 Aug 2023 13:51:22 +0200 Subject: [PATCH 2/2] Simplify confine statement in init service provider Rather than using a single complex statement, this uses multiple confine statements. --- lib/puppet/provider/service/init.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index db46436a0cf..e0f66df8678 100644 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -19,12 +19,9 @@ def self.defpath end # Debian and Ubuntu should use the Debian provider. + confine :false => ['Debian', 'Ubuntu'].include?(Puppet.runtime[:facter].value('operatingsystem')) # RedHat systems should use the RedHat provider. - confine :true => begin - os = Puppet.runtime[:facter].value(:operatingsystem) - family = Puppet.runtime[:facter].value(:osfamily) - !(os == 'Debian' || os == 'Ubuntu' || family == 'RedHat') - end + confine :false => Puppet.runtime[:facter].value('osfamily') == 'RedHat' # We can't confine this here, because the init path can be overridden. #confine :exists => defpath