[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#550401: return value of write ignored in nstx_tuntap.c



Package: nstx
Version: 1.1-beta6-5
Severity: normal
Tags: patch

Hi,

just found this when trying to build nstx on an Ubuntu system: In 
nstx_tuntap.c, the return value of write (for the tuntap file descriptor) is 
ignored, which means to ignore short writes or an EINTR.

Attached is a patch to fix this, would be excellent if you could include it.

Cheers,
   Stefan.


-- System Information:
Debian Release: squeeze/sid
  APT prefers karmic-updates
  APT policy: (500, 'karmic-updates'), (500, 'karmic-security'), (500, 'karmic')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.31-12-generic (SMP w/2 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
#! /bin/sh /usr/share/dpatch/dpatch-run
## fix-return-values.dpatch by  <sistpoty@ubuntu.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad nstx-1.1-beta6~/nstx_tuntap.c nstx-1.1-beta6/nstx_tuntap.c
--- nstx-1.1-beta6~/nstx_tuntap.c	2009-10-09 21:50:53.000000000 +0200
+++ nstx-1.1-beta6/nstx_tuntap.c	2009-10-09 21:53:01.000000000 +0200
@@ -266,7 +266,20 @@
 sendtun(const char *data, size_t len)
 {
 //   printf("Sent len %d, csum %d\n", len, checksum(data, len));
-   write(tfd, data, len);
+
+	size_t count;
+	ssize_t ret;
+
+	for (count = 0; count < len; count += ret) {
+		ret = write(tfd, data + count, len - count);
+
+		if (ret < 0) {
+			if (errno == EINTR) {
+				continue;
+			}
+			return;
+		}
+	}
 }
 
 void

Reply to: