From 596d947af66e03abfd9be4ea65002ba8d05ab010 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Thu, 16 Sep 2021 12:56:55 -0700 Subject: [PATCH] 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 --- vpnc-script | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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} -- 2.49.0