Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Boelen <michael.boelen@cisofy.com>2017-10-29 12:54:40 +0300
committerMichael Boelen <michael.boelen@cisofy.com>2017-10-29 12:54:40 +0300
commitebf16462a8b57dbf46e2a6ef7822fffcf77e351e (patch)
treea0cd50f8a0e2b9c221b378974d8b2e8900142c5d
parent011e6248c2b4acde11934f8875a308a1ca58f1b8 (diff)
Improve IsRunning function to match full process names
-rw-r--r--include/functions25
1 files changed, 20 insertions, 5 deletions
diff --git a/include/functions b/include/functions
index 65287143..dd80140c 100644
--- a/include/functions
+++ b/include/functions
@@ -1257,21 +1257,36 @@
IsRunning() {
if [ $# -eq 0 ]; then ExitFatal "Missing parameter when calling IsRunning function"; fi
+ pgrep_options="-x"
+ search=""
+ while [ $# -ge 1 ]; do
+ case $1 in
+ --full)
+ pgrep_options="-f" # replace -x with -f
+ ;;
+ *)
+ search="$1"
+ ;;
+ esac
+ shift # Go to next parameter
+ done
+
+ if [ -z "${search}" ]; then ExitFatal "Missing process to search for when using IsRunning function"; fi
RUNNING=0
if [ ! -z "${PGREPBINARY}" ]; then
- FIND=$(${PGREPBINARY} -x $1)
+ FIND=$(${PGREPBINARY} ${pgrep_options} "${search}" | ${TRBINARY} '\n' ' ')
else
PSOPTIONS=" -o args="
- if [ ${SHELL_IS_BUSYBOX} -eq 0 ]; then PSOPTIONS=" -o args= -C $1"; fi
- FIND=$(${PSBINARY} ${PSOPTIONS} | egrep "( |/)$1" | grep -v "grep")
+ if [ ${SHELL_IS_BUSYBOX} -eq 0 ]; then PSOPTIONS=" -o args= -C ${search}"; fi
+ FIND=$(${PSBINARY} ${PSOPTIONS} | egrep "( |/)${search}" | grep -v "grep")
fi
if [ ! -z "${FIND}" ]; then
RUNNING=1
- LogText "IsRunning: process '$1' found (${FIND})"
+ LogText "IsRunning: process '${search}' found (${FIND})"
return 0
else
- LogText "IsRunning: process '$1' not found"
+ LogText "IsRunning: process '${search}' not found"
return 1
fi
}