Print error when write() to tun device fails.
authorDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 7 Dec 2011 21:59:23 +0000 (21:59 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 7 Dec 2011 21:59:23 +0000 (21:59 +0000)
This happens on OpenBSD when writing IPv6 packets, for some reason.
Silent failure is not recommended; much better to bitch about it.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
tun.c

diff --git a/tun.c b/tun.c
index a66a196..6699143 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -668,10 +668,15 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout)
 #endif
                vpninfo->incoming_queue = this->next;
 
-               if (write(vpninfo->tun_fd, data, len) < 0 &&
-                   errno == ENOTCONN) {
-                       vpninfo->quit_reason = "Client connection terminated";
-                       return 1;
+               if (write(vpninfo->tun_fd, data, len) < 0) {
+                       /* Handle death of "script" socket */
+                       if (vpninfo->script_tun && errno == ENOTCONN) {
+                               vpninfo->quit_reason = "Client connection terminated";
+                               return 1;
+                       }
+                       vpn_progress(vpninfo, PRG_ERR,
+                                    _("Failed to write incoming packet: %s\n"),
+                                    strerror(errno));
                }
                free(this);
        }