Avoid using vpninfo->ifname before it's set.
authorJørgen Wahlberg <jorgen@wahlberg.no>
Sat, 27 Feb 2010 13:56:09 +0000 (14:56 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 27 Feb 2010 22:00:42 +0000 (23:00 +0100)
Commit 78e461ce2d74d7772578a07785fd96c7b784efae ("Set script environment
earlier...") was broken because we end up trying to set the $TUNDEV
environment variable before vpninfo->ifname has actually been set.

[dwmw2: slightly modified Jørgen's original patch so that we do actually
 set $TUNDEV later, otherwise the script won't work.]

Signed-off-by: Jørgen Wahlberg <jorgen@jaws.no>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
tun.c

diff --git a/tun.c b/tun.c
index cdae108..87955c2 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -239,7 +239,7 @@ static void set_script_env(struct openconnect_info *vpninfo)
                              sizeof(host), NULL, 0, NI_NUMERICHOST);
        if (!ret)
                setenv("VPNGATEWAY", host, 1);
-       setenv("TUNDEV", vpninfo->ifname, 1);
+
        setenv("reason", "connect", 1);
        unsetenv("CISCO_BANNER");
        unsetenv("CISCO_SPLIT_INC");
@@ -497,6 +497,7 @@ int setup_tun(struct openconnect_info *vpninfo)
 #endif
 #endif
                if (vpninfo->vpnc_script) {
+                       setenv("TUNDEV", vpninfo->ifname, 1);
                        script_config_tun(vpninfo);
                        /* We have to set the MTU for ourselves, because the script doesn't */
                        local_config_tun(vpninfo, 1);
@@ -596,7 +597,6 @@ void shutdown_tun(struct openconnect_info *vpninfo)
                kill(vpninfo->script_tun, SIGHUP);
        } else {
                if (vpninfo->vpnc_script) {
-                       setenv("TUNDEV", vpninfo->ifname, 1);
                        setenv("reason", "disconnect", 1);
                        if (system(vpninfo->vpnc_script) == -1) {
                                vpninfo->progress(vpninfo, PRG_ERR,