Commit f462e8f9 authored by Paolo 'Blaisorblade' Giarrusso's avatar Paolo 'Blaisorblade' Giarrusso Committed by Linus Torvalds

[PATCH] uml: better error reporting for read_output

Do precise error handling: print precise error messages, distinguishing short
reads and read errors.  This functions fails frequently enough for me so I
bothered doing this fix.
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Acked-by: default avatarJeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dc1561ac
...@@ -47,10 +47,12 @@ void tap_check_ips(char *gate_addr, unsigned char *eth_addr) ...@@ -47,10 +47,12 @@ void tap_check_ips(char *gate_addr, unsigned char *eth_addr)
} }
} }
/* Do reliable error handling as this fails frequently enough. */
void read_output(int fd, char *output, int len) void read_output(int fd, char *output, int len)
{ {
int remain, n, actual; int remain, ret, expected;
char c; char c;
char *str;
if(output == NULL){ if(output == NULL){
output = &c; output = &c;
...@@ -58,23 +60,31 @@ void read_output(int fd, char *output, int len) ...@@ -58,23 +60,31 @@ void read_output(int fd, char *output, int len)
} }
*output = '\0'; *output = '\0';
n = os_read_file(fd, &remain, sizeof(remain)); ret = os_read_file(fd, &remain, sizeof(remain));
if(n != sizeof(remain)){
printk("read_output - read of length failed, err = %d\n", -n); if (ret != sizeof(remain)) {
return; expected = sizeof(remain);
str = "length";
goto err;
} }
while(remain != 0){ while(remain != 0){
n = (remain < len) ? remain : len; expected = (remain < len) ? remain : len;
actual = os_read_file(fd, output, n); ret = os_read_file(fd, output, expected);
if(actual != n){ if (ret != expected) {
printk("read_output - read of data failed, " str = "data";
"err = %d\n", -actual); goto err;
return;
} }
remain -= actual; remain -= ret;
} }
return; return;
err:
if (ret < 0)
printk("read_output - read of %s failed, errno = %d\n", str, -ret);
else
printk("read_output - read of %s failed, read only %d of %d bytes\n", str, ret, expected);
} }
int net_read(int fd, void *buf, int len) int net_read(int fd, void *buf, int len)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment