From 875e99099e30278aadda6dba1476489f90300044 Mon Sep 17 00:00:00 2001 From: Sonu Saha Date: Tue, 3 May 2022 10:47:40 +0530 Subject: [PATCH] CFINSPEC-92: Extend be_running matcher to consider sleep state to be running Signed-off-by: Sonu Saha --- lib/inspec/resources/processes.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/inspec/resources/processes.rb b/lib/inspec/resources/processes.rb index 9418dab44..0e4772535 100644 --- a/lib/inspec/resources/processes.rb +++ b/lib/inspec/resources/processes.rb @@ -62,11 +62,13 @@ module Inspec::Resources # Matcher to check if the process is running def running? - # Check if Regex needs to be tightened. - # States value can be as: - # for Unix: R, R< or R+ - # for Windows "True" or "False" - states.any? and !!(states[0] =~ /True/ || states[0] =~ /^R+/) + # A process is considered running if: + # unix: it is in running(R) state or either of sleep state(D: Uninterruptible or S: Interruptible) + # windows: it is responding i.e. state is True. + + # Other codes like <(high priorty), N(low priority), +(foreground process group) etc. may appear after the state code in unix. + # Hence the regex used is /^statecode+/ where statecode is either R, S, or D. + states.any? and !!(states[0] =~ /True/ || states[0] =~ /^R+/ || states[0] =~ /^D+/ || states[0] =~ /^S+/) end filter = FilterTable.create