From: Daniel Lenski Date: Thu, 16 Sep 2021 19:51:43 +0000 (-0700) Subject: Provide the vpnc-script with our PID (as $VPNPID) X-Git-Tag: v8.20~66^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=e22750234dd78b32701dcd51dc42adfbd45d0e1b;p=users%2Fdwmw2%2Fopenconnect.git Provide the vpnc-script with our PID (as $VPNPID) This will enable a vpnc-script to more easily identify which VPN connection is calling it, in the case of multiple concurrent or "stacked" VPN connections. Because OpenConnect (and vpnc) invoke the vpnc-script via an intermediate shell process, the vpnc-script would otherwise need to determine its GRANDparent PID, which is an error-prone, and not easily portable, process. See https://gitlab.com/openconnect/vpnc-scripts/-/issues/28 and https://gitlab.com/openconnect/vpnc-scripts/-/merge_requests/36 for issues with the current approaches. Signed-off-by: Daniel Lenski --- diff --git a/script.c b/script.c index 7d1864d4..c4997619 100644 --- a/script.c +++ b/script.c @@ -23,7 +23,10 @@ #include #include #include -#ifndef _WIN32 +#ifdef _WIN32 +#include +#define getpid _getpid +#else #include #endif @@ -302,6 +305,7 @@ void prepare_script_env(struct openconnect_info *vpninfo) script_setenv(vpninfo, "CISCO_SPLIT_EXC", NULL, 0, 0); script_setenv_int(vpninfo, "INTERNAL_IP4_MTU", vpninfo->ip_info.mtu); + script_setenv_int(vpninfo, "VPNPID", (int)getpid()); if (vpninfo->idle_timeout) script_setenv_int(vpninfo, "IDLE_TIMEOUT", vpninfo->idle_timeout);