Improve error reporting for vpnc-script
authorDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 16 Jul 2012 19:19:44 +0000 (20:19 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 16 Jul 2012 19:48:24 +0000 (20:48 +0100)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
tun.c
www/changelog.xml

diff --git a/tun.c b/tun.c
index fdde7de..a28f9d4 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+#include <sys/wait.h>
 #include <string.h>
 #include <signal.h>
 #include <fcntl.h>
@@ -373,17 +374,33 @@ static void set_script_env(struct openconnect_info *vpninfo)
 
 int script_config_tun(struct openconnect_info *vpninfo, const char *reason)
 {
+       int ret;
+
        if (!vpninfo->vpnc_script)
                return 0;
 
        setenv("reason", reason, 1);
-       if (system(vpninfo->vpnc_script)) {
+       ret = system(vpninfo->vpnc_script);
+       if (ret == -1) {
                int e = errno;
                vpn_progress(vpninfo, PRG_ERR,
                             _("Failed to spawn script '%s' for %s: %s\n"),
                             vpninfo->vpnc_script, reason, strerror(e));
                return -e;
        }
+       if (!WIFEXITED(ret)) {
+               vpn_progress(vpninfo, PRG_ERR,
+                            _("Script '%s' exited abnormally (%x)\n"),
+                              vpninfo->vpnc_script, ret);
+               return -EIO;
+       }
+       ret = WEXITSTATUS(ret);
+       if (ret) {
+               vpn_progress(vpninfo, PRG_ERR,
+                            _("Script '%s' returned error %d\n"),
+                            vpninfo->vpnc_script, ret);
+               return -EIO;
+       }
        return 0;
 }
 
index 811edd6..7039947 100644 (file)
@@ -17,6 +17,7 @@
 <ul>
    <li><b>OpenConnect HEAD</b>
      <ul>
+       <li>Improve error handing when <tt>vpnc-script</tt> exits with error.</li>
        <li>Handle PKCS#11 tokens which won't list keys without login.</li>
      </ul><br/>
   </li>