From: Daniel Lenski Date: Thu, 16 Sep 2021 19:56:55 +0000 (-0700) Subject: Use $VPNPID when provided by OpenConnect X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=596d947a;p=users%2Fdwmw2%2Fvpnc-scripts.git Use $VPNPID when provided by OpenConnect See https://gitlab.com/openconnect/openconnect/-/merge_requests/278. Once merged, OpenConnect will send its PID to the vpnc-script as $VPNPID. The vpnc-script should use this in preference to trying to figure out its grandparent's PID on its own. Signed-off-by: Daniel Lenski --- diff --git a/vpnc-script b/vpnc-script index c58d4e2..3ebb56d 100755 --- a/vpnc-script +++ b/vpnc-script @@ -23,6 +23,7 @@ # List of parameters passed through environment #* reason -- why this script was called, one of: pre-init connect disconnect reconnect attempt-reconnect #* VPNGATEWAY -- VPN gateway address (always present) +#* VPNPID -- PID of the processing controlling the VPN (OpenConnect v9.0+) #* TUNDEV -- tunnel device (always present) #* IDLE_TIMEOUT -- gateway's idle timeout in seconds (OpenConnect v8.06+); unused #* INTERNAL_IP4_ADDRESS -- address (always present) @@ -92,11 +93,14 @@ HOOKS_DIR=/etc/vpnc # Use the PID of the controlling process (vpnc or OpenConnect) to # uniquely identify this VPN connection. Normally, the parent process # is a shell, and the grandparent's PID is the relevant one. -VPNPID=$PPID -PCMD=`ps -c -o cmd= -p $PPID` -case "$PCMD" in - *sh) VPNPID=`ps -o ppid= -p $PPID` ;; -esac +# OpenConnect v9.0+ provides VPNPID, so we don't need to determine it. +if [ -z "$VPNPID " ]; then + VPNPID=$PPID + PCMD=`ps -c -o cmd= -p $PPID` + case "$PCMD" in + *sh) VPNPID=`ps -o ppid= -p $PPID` ;; + esac +fi DEFAULT_ROUTE_FILE=/var/run/vpnc/defaultroute.${VPNPID} DEFAULT_ROUTE_FILE_IPV6=/var/run/vpnc/defaultroute_ipv6.${VPNPID}