From 6cd97ceba0080e6dd70d275a657cce7de234a64c Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 19 Oct 2021 17:56:39 +0100 Subject: [PATCH 1/2] Remove use of -p with lsof On machines with more modern kernels (>5.4 from testing so far) the useage of -b seems to conflict with the usage of -p. Whilst the usage of -b seems like a good idea to avoid blocks as we are tight looping on it, the usage of -p seems to require the usage of stat() (specifically in /proc) which -b forbids. All you get is a load of warnings (suppressable by -w) but never a positive result, which means that all servers are reported as "Failed to start". We are not keen on losing -b, so instead parse the output of lsof (using -F to format it) to check the if PIDs that it outputs match that we are looking for. Signed-off-by: Paul Elliott --- tests/ssl-opt.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 724d62791..2aad39c4f 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -566,7 +566,21 @@ if type lsof >/dev/null 2>/dev/null; then proto=TCP fi # Make a tight loop, server normally takes less than 1s to start. - while ! lsof -a -n -b -i "$proto:$1" -p "$2" >/dev/null 2>/dev/null; do + while true; do + SERVER_PIDS=$(lsof -a -n -b -i "$proto:$1" -F p | cut -c2-) + SERVER_FOUND=false + # When proxies are used, more than one PID can be listening on + # the same port. Each PID will be on its own line. + while read -r PID; do + if [[ $PID == $2 ]]; then + SERVER_FOUND=true + break + fi + done <<< "$SERVER_PIDS" + + if ($SERVER_FOUND == true); then + break + fi if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then echo "$3 START TIMEOUT" echo "$3 START TIMEOUT" >> $4 From ce77738d950ebbbee73d2ef5fabe5e71d4c871a7 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 20 Oct 2021 15:59:33 +0100 Subject: [PATCH 2/2] Remove bash specific code Use case pattern matching instead of multiline split, given there is only the well formatted PIDs to match on this should be safe. Signed-off-by: Paul Elliott --- tests/ssl-opt.sh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 2aad39c4f..d49f3f5be 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -559,6 +559,8 @@ has_mem_err() { # Wait for process $2 named $3 to be listening on port $1. Print error to $4. if type lsof >/dev/null 2>/dev/null; then wait_app_start() { + newline=' +' START_TIME=$(date +%s) if [ "$DTLS" -eq 1 ]; then proto=UDP @@ -567,20 +569,14 @@ if type lsof >/dev/null 2>/dev/null; then fi # Make a tight loop, server normally takes less than 1s to start. while true; do - SERVER_PIDS=$(lsof -a -n -b -i "$proto:$1" -F p | cut -c2-) - SERVER_FOUND=false - # When proxies are used, more than one PID can be listening on - # the same port. Each PID will be on its own line. - while read -r PID; do - if [[ $PID == $2 ]]; then - SERVER_FOUND=true - break - fi - done <<< "$SERVER_PIDS" - - if ($SERVER_FOUND == true); then - break - fi + SERVER_PIDS=$(lsof -a -n -b -i "$proto:$1" -F p) + # When we use a proxy, it will be listening on the same port we + # are checking for as well as the server and lsof will list both. + # If multiple PIDs are returned, each one will be on a separate + # line, each prepended with 'p'. + case ${newline}${SERVER_PIDS}${newline} in + *${newline}p${2}${newline}*) break;; + esac if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then echo "$3 START TIMEOUT" echo "$3 START TIMEOUT" >> $4