From e22750234dd78b32701dcd51dc42adfbd45d0e1b Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Thu, 16 Sep 2021 12:51:43 -0700 Subject: [PATCH] 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 --- script.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- 2.50.1