summaryrefslogtreecommitdiffstats
path: root/arch/sandbox/lib/common.c
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2007-11-28 10:12:38 +0100
committerMarc Kleine-Budde <mkl@pengutronix.de>2007-11-29 10:22:50 +0100
commit6574529bb5a233278e9886a93afeed70e9993b54 (patch)
treef15de55673e03f1bc742b6f101397ff2750a41a6 /arch/sandbox/lib/common.c
parentaff35bbe0968ff1fbde6814d43f5d85fd906d829 (diff)
downloadbarebox-6574529bb5a233278e9886a93afeed70e9993b54.tar.gz
barebox-6574529bb5a233278e9886a93afeed70e9993b54.tar.xz
[sandbox] add error handling to read
This patch adds propper error handling to the linux' read functions. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'arch/sandbox/lib/common.c')
-rw-r--r--arch/sandbox/lib/common.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/arch/sandbox/lib/common.c b/arch/sandbox/lib/common.c
index cd5c1c622a..5e08a6b197 100644
--- a/arch/sandbox/lib/common.c
+++ b/arch/sandbox/lib/common.c
@@ -146,7 +146,27 @@ void disable_interrupt(void)
int linux_read(int fd, void *buf, size_t count)
{
- return read(fd, buf, count);
+ ssize_t ret;
+
+ do {
+ ret = read(fd, buf, count);
+
+ if (ret == 0) {
+ printf("read on fd %d returned 0, device gone? - exiting\n", fd);
+ reset_cpu(0);
+ } else if (ret == -1) {
+ if (errno == EAGAIN)
+ usleep(100);
+ else if (errno == EINTR)
+ continue;
+ else {
+ printf("read on fd %d returned -1, errno %d - exiting\n", fd, errno);
+ reset_cpu(0);
+ }
+ }
+ } while (ret <= 0);
+
+ return (int)ret;
}
int linux_read_nonblock(int fd, void *buf, size_t count)
@@ -160,14 +180,11 @@ int linux_read_nonblock(int fd, void *buf, size_t count)
if (fcntl(fd, F_SETFL, oldflags | O_NONBLOCK) == -1)
goto err_out;
- ret = read(fd, buf, count);
+ ret = linux_read(fd, buf, count);
if (fcntl(fd, F_SETFL, oldflags) == -1)
goto err_out;
- if (ret == -1)
- usleep(100);
-
return ret;
err_out: