Skip to contentSkip to conversation

make t_server_null "server alive?" check more robust

PATCH In review Gert Doering 2 participants 3 messages Sep 18, 2024 – Sep 19, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make t_server_null "server alive?" check more robust

- use "$RUN_SUDO kill -0 $pid" to test if a given process is running, not "ps -p $pid" - the latter will not work if security.bsd.see_other_uids=0 is set

- produce proper error messages if pid files can not be found or are empty at server shutdown time

---
 tests/t_server_null_client.sh | 5 ++++-
 tests/t_server_null_server.sh | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)
tests/t_server_null_client.sh +4 -1
index e7dd3324..c1a25dfc 100755
@@ -87,7 +87,10 @@ while [ $count -lt $server_max_wait ]; do
     # the active server count as the processes won't be running.
     for i in `set|grep 'SERVER_NAME_'|cut -d "=" -f 2|tr -d "[\']"`; do
         server_pid=$(cat $i.pid 2> /dev/null)
-        if ps -p $server_pid > /dev/null 2>&1; then
+        if [ -z "$server_pid" ] ; then
+            continue
+        fi
+        if $RUN_SUDO kill -0 $server_pid > /dev/null 2>&1; then
             servers_up=$(( $servers_up + 1 ))
         fi
     done
tests/t_server_null_server.sh +5 -0
index e5906eec..32f0362d 100755
@@ -82,6 +82,11 @@ for PID_FILE in $server_pid_files
 do
     SERVER_PID=$(cat "${PID_FILE}")
 
+    if [ -z "$SERVER_PID" ] ; then
+        echo "WARNING: could not kill server ${PID_FILE}!"
+	continue
+    fi
+
     if [ -z "${RUN_SUDO}" ]; then
         $KILL_EXEC "${SERVER_PID}"
     else
Signature · 1 line
2.44.0
Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines · Gert Doering

- use "$RUN_SUDO kill -0 $pid" to test if a given process is running, not "ps -p $pid" - the latter will not work if security.bsd.see_other_uids=0 is set

- produce proper error messages if pid files can not be found or are empty at server shutdown time

---
 tests/t_server_null_client.sh | 5 ++++-
 tests/t_server_null_server.sh | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)
tests/t_server_null_client.sh +4 -1
index e7dd3324..c1a25dfc 100755
@@ -87,7 +87,10 @@ while [ $count -lt $server_max_wait ]; do
     # the active server count as the processes won't be running.
     for i in `set|grep 'SERVER_NAME_'|cut -d "=" -f 2|tr -d "[\']"`; do
         server_pid=$(cat $i.pid 2> /dev/null)
-        if ps -p $server_pid > /dev/null 2>&1; then
+        if [ -z "$server_pid" ] ; then
+            continue
+        fi
+        if $RUN_SUDO kill -0 $server_pid > /dev/null 2>&1; then
             servers_up=$(( $servers_up + 1 ))
         fi
     done
tests/t_server_null_server.sh +0 -0
index e5906eec..32f0362d 100755

tests/t_server_null_server.sh for PID_FILE in $server_pid_files · line 87

Quoted 6 lines
tests/t_server_null_server.sh +3 -0
@@ -82,6 +82,11 @@ for PID_FILE in $server_pid_files
 do
     SERVER_PID=$(cat "${PID_FILE}")
 
+    if [ -z "$SERVER_PID" ] ; then
+        echo "WARNING: could not kill server ${PID_FILE}!"
+	continue

Indentation looks slightly wrong.

Otherwise looks good to me, so

Regards,

Signature · 1 line
  Frank Lichtenheld
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: make t_server_null 'server alive?' check more robust

In reply to Gert Doering

Thanks for the review. Indent fixed, that was a <tab> that sneaked in.

Patch has been applied to the master branch.

commit b322690394b75a9d4987d4b27107ccb01bbcd90e

Author: Gert Doering
Date:   Wed Sep 18 18:29:17 2024 +0200
     make t_server_null 'server alive?' check more robust

     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg29314.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering