aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libdvbv5/dvb-dev-local.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-07 14:40:50 (GMT)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-07 18:07:47 (GMT)
commit6fd54b7007114f99b770f76a3162888b395829b4 (patch)
tree575d9f0a18e28d24c4ca01dea3ab03a8c2259a0e /lib/libdvbv5/dvb-dev-local.c
parent19d47ff1cbedfc967a07a74ba3ecf90c66619816 (diff)
libdvbv5: better handle local errors
There are some mess at error handling logic: sometimes, it returns errors as positive values, sometimes as negative. Also, on several places, it just return a random negative number. Always use negative numbers for errors, and use the Kernel error codes, to make it more portable. Also, as errors can now be reported to the remote end, if the error is filled at errno, return it via the return function parameter where possible. 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.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index 184ba6f..69e4acc 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -57,7 +57,7 @@ static int handle_device_change(struct dvb_device_priv *dvb,
p = udev_device_get_sysname(dev);
if (!p) {
dvb_logerr(_("udev_device_get_sysname failed"));
- return -1;
+ return -ENODEV;
}
for (i = 0; i < dvb->d.num_devices; i++) {
@@ -71,7 +71,7 @@ static int handle_device_change(struct dvb_device_priv *dvb,
sizeof(*dvb->d.devices) * dvb->d.num_devices);
if (!p) {
dvb_logerr(_("Can't remove a device from the list of DVB devices"));
- return -2;
+ return -ENODEV;
}
break;
}
@@ -201,7 +201,7 @@ added:
err:
free_dvb_dev(dvb_dev);
- return -1;
+ return -ENODEV;
}
static int dvb_local_find(struct dvb_device_priv *dvb, int enable_monitor)
@@ -220,7 +220,7 @@ static int dvb_local_find(struct dvb_device_priv *dvb, int enable_monitor)
dvb->udev = udev_new();
if (!dvb->udev) {
dvb_logerr(_("Can't create an udev object\n"));
- return -1;
+ return -ENOMEM;
}
dvb->monitor = enable_monitor;
@@ -416,7 +416,7 @@ static int dvb_local_close(struct dvb_open_descriptor *open_dev)
/* Should never happen */
dvb_logerr(_("Couldn't free device\n"));
- return -1;
+ return -ENODEV;
}
#define MAX_TIME 10 /* 1.0 seconds */
@@ -450,11 +450,13 @@ static int dvb_local_dmx_stop(struct dvb_open_descriptor *open_dev)
int ret, fd = open_dev->fd;
if (dev->dvb_type != DVB_DEVICE_DEMUX)
- return -1;
+ return -EINVAL;
ret = xioctl(fd, DMX_STOP);
- if (ret == -1)
+ if (ret == -1) {
dvb_perror(_("DMX_STOP failed"));
+ return -errno;
+ }
return 0;
}
@@ -468,11 +470,11 @@ static int dvb_local_set_bufsize(struct dvb_open_descriptor *open_dev,
int fd = open_dev->fd;
if (dev->dvb_type != DVB_DEVICE_DEMUX && dev->dvb_type != DVB_DEVICE_DVR)
- return -1;
+ return -EINVAL;
if (xioctl(fd, DMX_SET_BUFFER_SIZE, buffersize) == -1) {
dvb_perror(_("DMX_SET_BUFFER_SIZE failed"));
- return -1;
+ return -errno;
}
return 0;
@@ -488,11 +490,13 @@ static ssize_t dvb_local_read(struct dvb_open_descriptor *open_dev,
ssize_t ret;
if (dev->dvb_type != DVB_DEVICE_DEMUX && dev->dvb_type != DVB_DEVICE_DVR)
- return -1;
+ return -EINVAL;
ret = read(fd, buf, count);
- if (ret == -1)
+ if (ret == -1) {
dvb_perror("read()");
+ return -errno;
+ }
return ret;
}
@@ -508,7 +512,7 @@ static int dvb_local_dmx_set_pesfilter(struct dvb_open_descriptor *open_dev,
int fd = open_dev->fd;
if (dev->dvb_type != DVB_DEVICE_DEMUX)
- return -1;
+ return -EINVAL;
/* Failing here is not fatal, so no need to handle error condition */
if (bufsize)
@@ -525,7 +529,7 @@ static int dvb_local_dmx_set_pesfilter(struct dvb_open_descriptor *open_dev,
if (xioctl(fd, DMX_SET_PES_FILTER, &pesfilter) == -1) {
dvb_logerr(_("DMX_SET_PES_FILTER failed (PID = 0x%04x): %d %m"),
pid, errno);
- return -1;
+ return -errno;
}
return 0;
@@ -545,7 +549,7 @@ static int dvb_local_dmx_set_section_filter(struct dvb_open_descriptor *open_dev
int fd = open_dev->fd;
if (dev->dvb_type != DVB_DEVICE_DEMUX)
- return -1;
+ return -EINVAL;
if (filtsize > DMX_FILTER_SIZE)
filtsize = DMX_FILTER_SIZE;
@@ -566,7 +570,7 @@ static int dvb_local_dmx_set_section_filter(struct dvb_open_descriptor *open_dev
if (xioctl(fd, DMX_SET_FILTER, &sctfilter) == -1) {
dvb_logerr(_("DMX_SET_FILTER failed (PID = 0x%04x): %d %m"),
pid, errno);
- return -1;
+ return -errno;
}
return 0;
@@ -587,7 +591,7 @@ static int dvb_local_dmx_get_pmt_pid(struct dvb_open_descriptor *open_dev, int s
int section_length;
if (dev->dvb_type != DVB_DEVICE_DEMUX)
- return -1;
+ return -EINVAL;
memset(&f, 0, sizeof(f));
f.pid = 0;
@@ -598,7 +602,7 @@ static int dvb_local_dmx_get_pmt_pid(struct dvb_open_descriptor *open_dev, int s
if (xioctl(fd, DMX_SET_FILTER, &f) == -1) {
dvb_perror("ioctl DMX_SET_FILTER failed");
- return -1;
+ return -errno;
}
while (!patread){
@@ -606,7 +610,7 @@ static int dvb_local_dmx_get_pmt_pid(struct dvb_open_descriptor *open_dev, int s
count = read(fd, buf, sizeof(buft));
if (count < 0) {
dvb_perror("read_sections: read error");
- return -1;
+ return -errno;
}
section_length = ((buf[1] & 0x0f) << 8) | buf[2];

Privacy Policy