mirror of
https://github.com/CISOfy/lynis.git
synced 2025-07-27 07:44:14 +02:00
Improve IsRunning function to match full process names
This commit is contained in:
parent
011e6248c2
commit
ebf16462a8
@ -1257,21 +1257,36 @@
|
|||||||
|
|
||||||
IsRunning() {
|
IsRunning() {
|
||||||
if [ $# -eq 0 ]; then ExitFatal "Missing parameter when calling IsRunning function"; fi
|
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
|
RUNNING=0
|
||||||
if [ ! -z "${PGREPBINARY}" ]; then
|
if [ ! -z "${PGREPBINARY}" ]; then
|
||||||
FIND=$(${PGREPBINARY} -x $1)
|
FIND=$(${PGREPBINARY} ${pgrep_options} "${search}" | ${TRBINARY} '\n' ' ')
|
||||||
else
|
else
|
||||||
PSOPTIONS=" -o args="
|
PSOPTIONS=" -o args="
|
||||||
if [ ${SHELL_IS_BUSYBOX} -eq 0 ]; then PSOPTIONS=" -o args= -C $1"; fi
|
if [ ${SHELL_IS_BUSYBOX} -eq 0 ]; then PSOPTIONS=" -o args= -C ${search}"; fi
|
||||||
FIND=$(${PSBINARY} ${PSOPTIONS} | egrep "( |/)$1" | grep -v "grep")
|
FIND=$(${PSBINARY} ${PSOPTIONS} | egrep "( |/)${search}" | grep -v "grep")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "${FIND}" ]; then
|
if [ ! -z "${FIND}" ]; then
|
||||||
RUNNING=1
|
RUNNING=1
|
||||||
LogText "IsRunning: process '$1' found (${FIND})"
|
LogText "IsRunning: process '${search}' found (${FIND})"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
LogText "IsRunning: process '$1' not found"
|
LogText "IsRunning: process '${search}' not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user