]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Provide the vpnc-script with our PID (as $VPNPID)
authorDaniel Lenski <dlenski@gmail.com>
Thu, 16 Sep 2021 19:51:43 +0000 (12:51 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Thu, 16 Sep 2021 20:13:32 +0000 (13:13 -0700)
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 <dlenski@gmail.com>
script.c

index 7d1864d4b63fac493851ac834ab0fc13a728704a..c499761924fdd0ee950681c87feb9c507ff22cf6 100644 (file)
--- a/script.c
+++ b/script.c
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#ifndef _WIN32
+#ifdef _WIN32
+#include <process.h>
+#define getpid _getpid
+#else
 #include <sys/wait.h>
 #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);