aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libdvbv5/dvb-dev-local.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-08 09:46:45 (GMT)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-08-08 09:46:45 (GMT)
commit7c0f3865619f580461a5ee46da48cde5e9ca1cd3 (patch)
tree3a5d9c78321539a9ac549d32d9abe6a6200e5ea1 /lib/libdvbv5/dvb-dev-local.c
parent1b4dce8c38833a5d93e41efe5065a9249b500e45 (diff)
libdvbv5: fix device changes notification
Added an option at dvb-fe-tool to monitor device insert/removal, and fixed some bugs at its logic. 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.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index fc19f5d..f514794 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -62,7 +62,7 @@ static int handle_device_change(struct dvb_device_priv *dvb,
struct udev_device *parent = NULL;
struct dvb_dev_list dev_list, *dvb_dev;
enum dvb_dev_change_type type;
- const char *bus_type, *p;
+ const char *bus_type, *p, *sysname;
char *buf;
int i, ret;
@@ -70,24 +70,29 @@ static int handle_device_change(struct dvb_device_priv *dvb,
if (!strcmp(action,"add")) {
type = DVB_DEV_ADD;
} else {
- p = udev_device_get_sysname(dev);
- if (!p) {
+ sysname = udev_device_get_sysname(dev);
+ if (!sysname) {
dvb_logerr(_("udev_device_get_sysname failed"));
return -ENODEV;
}
for (i = 0; i < dvb->d.num_devices; i++) {
- if (!strcmp(p, dvb->d.devices[i].sysname)) {
+ if (!strcmp(sysname, dvb->d.devices[i].sysname)) {
memmove(&dvb->d.devices[i],
&dvb->d.devices[i + 1],
sizeof(*dvb->d.devices) * (dvb->d.num_devices - i));
dvb->d.num_devices--;
- p = realloc(dvb->d.devices,
- sizeof(*dvb->d.devices) * dvb->d.num_devices);
- if (!p) {
- dvb_logerr(_("Can't remove a device from the list of DVB devices"));
- return -ENODEV;
+ if (!dvb->d.num_devices) {
+ free(dvb->d.devices);
+ dvb->d.devices = NULL;
+ } else {
+ p = realloc(dvb->d.devices,
+ sizeof(*dvb->d.devices) * dvb->d.num_devices);
+ if (!p) {
+ dvb_logerr(_("Can't remove a device from the list of DVB devices"));
+ return -ENODEV;
+ }
}
break;
}
@@ -96,7 +101,7 @@ static int handle_device_change(struct dvb_device_priv *dvb,
/* Return, if the device was removed */
if (!strcmp(action,"remove")) {
if (priv->notify_dev_change)
- priv->notify_dev_change(syspath,
+ priv->notify_dev_change(strdup(sysname),
DVB_DEV_REMOVE);
return 0;
}
@@ -217,7 +222,7 @@ static int handle_device_change(struct dvb_device_priv *dvb,
}
added:
if (priv->notify_dev_change)
- priv->notify_dev_change(syspath, type);
+ priv->notify_dev_change(strdup(dvb_dev->sysname), type);
dvb_dev_dump_device(_("Found dvb %s device: %s"), parms, dvb_dev);
return 0;

Privacy Policy