From f89f611ca913fa715f6b4b0a78e15eec1841fa10 Mon Sep 17 00:00:00 2001 From: Kurt H Maier Date: Tue, 7 May 2019 13:01:17 -0700 Subject: [PATCH 1/3] probe-utils.pm: refactor switch statement switch() is only available if explicitly declared. switch to a for block using elsif to return a value. --- xCAT-probe/lib/perl/probe_utils.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/xCAT-probe/lib/perl/probe_utils.pm b/xCAT-probe/lib/perl/probe_utils.pm index c45fc753b..239adf963 100644 --- a/xCAT-probe/lib/perl/probe_utils.pm +++ b/xCAT-probe/lib/perl/probe_utils.pm @@ -252,17 +252,20 @@ sub is_selinux_enable { #------------------------------------------ sub is_selinux_enforcing { + my $retval = 0; if (-e "/usr/sbin/getenforce") { my $enforce_mode = `/usr/sbin/getenforce`; chomp $enforce_mode; - switch ($enforce_mode) { - case "Disabled" { return 0; } - case "Permissive" { return 0; } - case "Enforcing" { return 1; } - else { return 0; } + for ($enforce_mode) { + if (/Disabled/) { $retval = 0; } + elsif (/Permissive/) { $retval = 0; } + elsif (/Enforcing/) { $retval = 1; } + else { $retval = 0; } + } } else { - return 0; + $retval = 0; } + return $retval; } #------------------------------------------ From 59f8845d37796d182f9366e52ad5cd612fbb058f Mon Sep 17 00:00:00 2001 From: Kurt H Maier Date: Tue, 7 May 2019 13:52:34 -0700 Subject: [PATCH 2/3] probe_utils: remove extraneous else block --- xCAT-probe/lib/perl/probe_utils.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/xCAT-probe/lib/perl/probe_utils.pm b/xCAT-probe/lib/perl/probe_utils.pm index 239adf963..69d427dcd 100644 --- a/xCAT-probe/lib/perl/probe_utils.pm +++ b/xCAT-probe/lib/perl/probe_utils.pm @@ -262,8 +262,6 @@ sub is_selinux_enforcing { elsif (/Enforcing/) { $retval = 1; } else { $retval = 0; } } - } else { - $retval = 0; } return $retval; } From e8aa0c8599c54efac887a0eea64aaa70cb53062b Mon Sep 17 00:00:00 2001 From: Kurt H Maier Date: Tue, 7 May 2019 14:05:25 -0700 Subject: [PATCH 3/3] probe_utils: simplify selinux enforcing check --- xCAT-probe/lib/perl/probe_utils.pm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/xCAT-probe/lib/perl/probe_utils.pm b/xCAT-probe/lib/perl/probe_utils.pm index 69d427dcd..71e3ae8d6 100644 --- a/xCAT-probe/lib/perl/probe_utils.pm +++ b/xCAT-probe/lib/perl/probe_utils.pm @@ -256,11 +256,8 @@ sub is_selinux_enforcing { if (-e "/usr/sbin/getenforce") { my $enforce_mode = `/usr/sbin/getenforce`; chomp $enforce_mode; - for ($enforce_mode) { - if (/Disabled/) { $retval = 0; } - elsif (/Permissive/) { $retval = 0; } - elsif (/Enforcing/) { $retval = 1; } - else { $retval = 0; } + if ($enforce_mode eq "Enforcing") { + $retval = 1; } } return $retval;