From 236d8139682eb8b67c1f6309f96eab0050203c08 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Fri, 6 Dec 2024 16:12:27 +0900 Subject: [PATCH] Fixed bugs about defunct processes and mis-coding (#121) --- bin/run.sh | 6 ++++-- lib/openstackapiv3.js | 1 + tests/auto_control_subprocess.sh | 12 ++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/run.sh b/bin/run.sh index ba5a718..1d2220f 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -153,7 +153,8 @@ stop_old_process() # If processes are running yet, try to kill it. # for _ONE_PID in ${ALL_CHILD_PIDS}; do - if ps -p "${_ONE_PID}" >/dev/null 2>&1; then + # shellcheck disable=SC2009 + if ! ps -ax | grep -v grep | grep -v defunct | grep -q "${_ONE_PID}"; then kill -KILL "${_ONE_PID}" >/dev/null 2>&1 fi done @@ -163,7 +164,8 @@ stop_old_process() # Result # for _ONE_PID in ${ALL_CHILD_PIDS}; do - if ps -p "${_ONE_PID}" >/dev/null 2>&1; then + # shellcheck disable=SC2009 + if ! ps -ax | grep -v grep | grep -v defunct | grep -q "${_ONE_PID}"; then echo "[ERROR] Could not stop old processes." return 1 fi diff --git a/lib/openstackapiv3.js b/lib/openstackapiv3.js index 9fc2621..d5e34ca 100644 --- a/lib/openstackapiv3.js +++ b/lib/openstackapiv3.js @@ -221,6 +221,7 @@ function rawGetUserUnscopedTokenV3(uname, passwd, callback) resobj.region = keystone_ep.region.toLowerCase(); resobj.token_seed = JSON.stringify({ publisher: 'OPENSTACKV3' }); _callback(null, resobj); + return; }); }); req.on('error', function(exception) { diff --git a/tests/auto_control_subprocess.sh b/tests/auto_control_subprocess.sh index f55cb2b..af51a04 100755 --- a/tests/auto_control_subprocess.sh +++ b/tests/auto_control_subprocess.sh @@ -173,7 +173,8 @@ if [ "${EXEC_MODE}" = "start" ]; then sleep "${RUN_INTERVAL}" fi - if ! ps -p "${CHILD_PROCESS_PID}" >/dev/null 2>&1; then + # shellcheck disable=SC2009 + if ! ps -ax | grep -v grep | grep -v defunct | grep -q "${CHILD_PROCESS_PID}"; then echo "[ERROR] Could not start child process : ${CHILD_PROCESS_CMD}" exit 1 fi @@ -189,7 +190,8 @@ else CHILD_PROCESS_PID="$(tr -d '\n' < "${CHILD_PROCESS_PIDFILE}")" - if ps -p "${CHILD_PROCESS_PID}" >/dev/null 2>&1; then + # shellcheck disable=SC2009 + if ! ps -ax | grep -v grep | grep -v defunct | grep -q "${CHILD_PROCESS_PID}"; then # # Try stop # @@ -200,7 +202,8 @@ else sleep "${RUN_INTERVAL}" fi - if ps -p "${CHILD_PROCESS_PID}" >/dev/null 2>&1; then + # shellcheck disable=SC2009 + if ! ps -ax | grep -v grep | grep -v defunct | grep -q "${CHILD_PROCESS_PID}"; then # # Retry stop # @@ -211,7 +214,8 @@ else sleep "${RUN_INTERVAL}" fi - if ps -p "${CHILD_PROCESS_PID}" >/dev/null 2>&1; then + # shellcheck disable=SC2009 + if ! ps -ax | grep -v grep | grep -v defunct | grep -q "${CHILD_PROCESS_PID}"; then echo "[ERROR] Could not stop process : ${CHILD_PROCESS_NAME}" exit 1 fi