Skip to content

Commit

Permalink
[PATCH] uml: better error reporting for read_output
Browse files Browse the repository at this point in the history
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: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Acked-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Paolo 'Blaisorblade' Giarrusso authored and Linus Torvalds committed Feb 24, 2006
1 parent dc1561a commit f462e8f
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions arch/um/drivers/net_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,44 @@ 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)
{
int remain, n, actual;
int remain, ret, expected;
char c;
char *str;

if(output == NULL){
output = &c;
len = sizeof(c);
}

*output = '\0';
n = os_read_file(fd, &remain, sizeof(remain));
if(n != sizeof(remain)){
printk("read_output - read of length failed, err = %d\n", -n);
return;
ret = os_read_file(fd, &remain, sizeof(remain));

if (ret != sizeof(remain)) {
expected = sizeof(remain);
str = "length";
goto err;
}

while(remain != 0){
n = (remain < len) ? remain : len;
actual = os_read_file(fd, output, n);
if(actual != n){
printk("read_output - read of data failed, "
"err = %d\n", -actual);
return;
expected = (remain < len) ? remain : len;
ret = os_read_file(fd, output, expected);
if (ret != expected) {
str = "data";
goto err;
}
remain -= actual;
remain -= ret;
}

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)
Expand Down

0 comments on commit f462e8f

Please sign in to comment.