aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libdvbv5/dvb-dev-local.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2017-12-14 11:16:10 (GMT)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-12-14 11:24:39 (GMT)
commit20a4104218c33cc4abe90fb83f325ea108d9dfbd (patch)
treea7c6e16cbb548789ce1a6992d1b5b9d2534bc983 /lib/libdvbv5/dvb-dev-local.c
parent6262606e396a7108d6621791d5a77588a7c3996e (diff)
libdvbv5: be sure that interruped reads will be handled
It is possible that the read() ioctl would return a temporary error, as documented at glibc texinfo pages: "A signal can arrive and be handled while an I/O primitive such as ‘open’ or ‘read’ is waiting for an I/O device. If the signal handler returns, the system faces the question: what should happen next? POSIX specifies one approach: make the primitive fail right away. The error code for this kind of failure is ‘EINTR’. This is flexible, but usually inconvenient. Typically, POSIX applications that use signal handlers must check for ‘EINTR’ after each library function that can return it, in order to try the call again. Often programmers forget to check, which is a common source of error. The GNU C Library provides a convenient way to retry a call after a temporary failure, with the macro ‘TEMP_FAILURE_RETRY’" So, improve the read logic in order to handle such cases. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'lib/libdvbv5/dvb-dev-local.c')
-rw-r--r--lib/libdvbv5/dvb-dev-local.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index 97bf309..8bc99d1 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -609,7 +609,7 @@ static ssize_t dvb_local_read(struct dvb_open_descriptor *open_dev,
}
}
- ret = read(fd, buf, count);
+ ret = TEMP_FAILURE_RETRY(read(fd, buf, count));
if (ret == -1) {
if (errno != EOVERFLOW && errno != EAGAIN)
dvb_perror("read()");
@@ -724,8 +724,9 @@ static int dvb_local_dmx_get_pmt_pid(struct dvb_open_descriptor *open_dev, int s
}
while (!patread){
- if (((count = read(fd, buf, sizeof(buft))) < 0) && errno == EOVERFLOW)
- count = read(fd, buf, sizeof(buft));
+ count = TEMP_FAILURE_RETRY(read(fd, buf, sizeof(buft)));
+ if (count < 0 && errno == EOVERFLOW)
+ count = TEMP_FAILURE_RETRY(read(fd, buf, sizeof(buft)));
if (count < 0) {
dvb_perror("read_sections: read error");
return -errno;

Privacy Policy