aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-06 19:12:13 (GMT)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-06 19:13:45 (GMT)
commita95865a40c39e5a9d39119ffe72724b7624077d0 (patch)
tree86bedc9d9f0c358deb6d39800ce7c406d159eb56
parent49010212a7f0e0643083d5f1f9b185c8cb1ea156 (diff)
libdvbv5: Fix remote read()
There were several small bugs making read() unreliable when used over a remote connection. Address them. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--lib/libdvbv5/dvb-dev-local.c4
-rw-r--r--lib/libdvbv5/dvb-dev-remote.c27
-rw-r--r--utils/dvb/dvbv5-daemon.c44
3 files changed, 40 insertions, 35 deletions
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index 796571d..4632991 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -16,6 +16,10 @@
* Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
+#define _FILE_OFFSET_BITS 64
+#define _LARGEFILE_SOURCE 1
+#define _LARGEFILE64_SOURCE 1
+
#include <libudev.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libdvbv5/dvb-dev-remote.c b/lib/libdvbv5/dvb-dev-remote.c
index 1353b85..640e2bd 100644
--- a/lib/libdvbv5/dvb-dev-remote.c
+++ b/lib/libdvbv5/dvb-dev-remote.c
@@ -16,6 +16,10 @@
* Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
+#define _FILE_OFFSET_BITS 64
+#define _LARGEFILE_SOURCE 1
+#define _LARGEFILE64_SOURCE 1
+
#include <libudev.h>
#include <stdio.h>
#include <stdlib.h>
@@ -234,7 +238,8 @@ static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,
p += ret;
- ret = write(fd, buf, p - buf);
+ pthread_mutex_lock(&msg->lock);
+ ret = send(fd, buf, p - buf, MSG_CONFIRM);
if (ret < 0 || (ret < p - buf)) {
pthread_mutex_destroy(&msg->lock);
pthread_cond_destroy(&msg->cond);
@@ -525,7 +530,6 @@ static int dvb_remote_get_version(struct dvb_device_priv *dvb)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -567,7 +571,6 @@ static int dvb_remote_find(struct dvb_device_priv *dvb, int enable_monitor)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -600,7 +603,6 @@ static int dvb_remote_stop_monitor(struct dvb_device_priv *dvb)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -638,7 +640,6 @@ struct dvb_dev_list *dvb_remote_seek_by_sysname(struct dvb_device_priv *dvb,
if (!msg)
return NULL;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -709,7 +710,6 @@ static struct dvb_open_descriptor *dvb_remote_open(struct dvb_device_priv *dvb,
if (!msg)
return NULL;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -760,7 +760,6 @@ static int dvb_remote_close(struct dvb_open_descriptor *open_dev)
if (!msg)
goto error;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -812,7 +811,6 @@ static int dvb_remote_dmx_stop(struct dvb_open_descriptor *open_dev)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -848,7 +846,6 @@ static int dvb_remote_set_bufsize(struct dvb_open_descriptor *open_dev,
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -886,7 +883,6 @@ static ssize_t dvb_remote_read(struct dvb_open_descriptor *open_dev,
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -918,6 +914,10 @@ error:
pthread_mutex_unlock(&msg->lock);
free_msg(dvb, msg);
+
+ if (ret < 0)
+ errno = -ret;
+
return ret;
}
@@ -936,7 +936,6 @@ static int dvb_remote_dmx_set_pesfilter(struct dvb_open_descriptor *open_dev,
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -977,7 +976,6 @@ static int dvb_remote_dmx_set_section_filter(struct dvb_open_descriptor *open_de
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -1012,7 +1010,6 @@ static int dvb_remote_dmx_get_pmt_pid(struct dvb_open_descriptor *open_dev, int
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -1046,7 +1043,6 @@ int dvb_remote_fe_set_sys(struct dvb_v5_fe_parms *p, fe_delivery_system_t sys)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -1083,7 +1079,6 @@ int dvb_remote_fe_get_parms(struct dvb_v5_fe_parms *par)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -1227,7 +1222,6 @@ int dvb_remote_fe_set_parms(struct dvb_v5_fe_parms *par)
if (!msg)
goto error;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
@@ -1269,7 +1263,6 @@ int dvb_remote_fe_get_stats(struct dvb_v5_fe_parms *par)
if (!msg)
return -1;
- pthread_mutex_lock(&msg->lock);
ret = pthread_cond_wait(&msg->cond, &msg->lock);
if (ret < 0) {
dvb_logerr("error waiting for %s response", msg->cmd);
diff --git a/utils/dvb/dvbv5-daemon.c b/utils/dvb/dvbv5-daemon.c
index 8695222..163acf6 100644
--- a/utils/dvb/dvbv5-daemon.c
+++ b/utils/dvb/dvbv5-daemon.c
@@ -21,6 +21,10 @@
#define _XOPEN_SOURCE 600
#define WIN32_LEAN_AND_MEAN /* required by xmlrpc-c/server_abyss.h */
+#define _FILE_OFFSET_BITS 64
+#define _LARGEFILE_SOURCE 1
+#define _LARGEFILE64_SOURCE 1
+
#include <argp.h>
#include <config.h>
#include <endian.h>
@@ -235,7 +239,7 @@ static void free_opendevs(void *node)
struct dvb_descriptors *desc = node;
if (verbose)
- dbg("closing dev %p\n", desc, desc->open_dev);
+ dbg("closing dev %p", desc, desc->open_dev);
dvb_dev_close(desc->open_dev);
free (desc);
@@ -680,7 +684,7 @@ static int dev_read(uint32_t seq, char *cmd, int fd,
char *inbuf, ssize_t insize)
{
struct dvb_open_descriptor *open_dev;
- int uid, ret, i;
+ int uid, ret, read_ret = -1, i;
char databuf[REMOTE_BUF_SIZE];
char buf[REMOTE_BUF_SIZE], *p = buf;
size_t size = sizeof(buf);
@@ -701,30 +705,34 @@ static int dev_read(uint32_t seq, char *cmd, int fd,
goto error;
}
- ret = dvb_dev_read(open_dev, databuf, count);
-
- if (verbose)
- dbg("read %zd bytes", ret);
-
- count = ret;
+ read_ret = dvb_dev_read(open_dev, databuf, count);
+ if (read_ret < 0) {
+ read_ret = -errno;
+ if (verbose)
+ dbg("%d: read error: %d", seq, read_ret);
+ } else {
+ if (verbose)
+ dbg("%d: read %d bytes", seq, read_ret);
+ }
error:
- if (ret < 0)
- return ret;
-
- ret = prepare_data(p, size, "%i%s%i", seq, cmd, ret);
- if (ret < 0)
+ ret = prepare_data(p, size, "%i%s%i", seq, cmd, read_ret);
+ if (ret < 0) {
+ err("Failed to prepare answer to dvb_read()");
return ret;
+ }
p += ret;
size -= ret;
- if (size < count) {
- dbg("buffer to short to store read data");
- return -1;
+ if (read_ret > 0) {
+ if (size < read_ret) {
+ dbg("buffer to short to store read data");
+ return -1;
+ }
+ memcpy(p, databuf, read_ret);
+ p += read_ret;
}
- memcpy(p, databuf, count);
- p += count;
return send_buf(fd, buf, p - buf);
}

Privacy Policy