Browse code

t_client.sh: Make OpenVPN write PID file to avoid various sudo issues

This resolves an issue where $! returns the PID of the sudo process instead
of the PID of OpenVPN and when sudo does not properly propagate signales
down to OpenVPN.

Trac: #738
Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1474104026-20615-1-git-send-email-davids@openvpn.net>
URL: http://www.mail-archive.com/search?l=mid&q=1474104026-20615-1-git-send-email-davids@openvpn.net
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit e0926ebfe55347843af701216be9598827a1367a)

David Sommerseth authored on 2016/09/17 18:20:26
Showing 1 changed files
... ...
@@ -233,10 +233,14 @@ do
233 233
 	continue
234 234
     fi
235 235
 
236
+    pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
237
+    openvpn_conf="$openvpn_conf --writepid $pidfile"
236 238
     echo " run openvpn $openvpn_conf"
237 239
     echo "# src/openvpn/openvpn $openvpn_conf" >$LOGDIR/$SUF:openvpn.log
238 240
     $RUN_SUDO "${top_builddir}/src/openvpn/openvpn" $openvpn_conf >>$LOGDIR/$SUF:openvpn.log &
239
-    opid=$!
241
+    sleep 3  # Wait for OpenVPN to initialize and have had time to write the pid file
242
+    opid=`cat $pidfile`
243
+    echo "  OpenVPN running with PID $opid"
240 244
 
241 245
     # make sure openvpn client is terminated in case shell exits
242 246
     trap "$RUN_SUDO kill $opid" 0