From ebf16462a8b57dbf46e2a6ef7822fffcf77e351e Mon Sep 17 00:00:00 2001 From: Michael Boelen Date: Sun, 29 Oct 2017 10:54:40 +0100 Subject: [PATCH] Improve IsRunning function to match full process names --- include/functions | 25 ++++++++++++++++++++----- 1 file 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 }