changeset 2130:5755e8d89012 draft

Allow dev to recieve errors from managers handle_device.
author Roy Marples <roy@marples.name>
date Sat, 14 Sep 2013 08:50:41 +0000
parents b3297a3dd2fc
children 803530152d7c
files dev.c dev.h dev/udev.c
diffstat 3 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/dev.c	Thu Sep 12 22:11:04 2013 +0000
+++ b/dev.c	Sat Sep 14 08:50:41 2013 +0000
@@ -143,13 +143,22 @@
 	return r;
 }
 
+static void
+dev_handle_data(__unused void *arg)
+{
+
+	if (dev->handle_device() == -1) {
+		/* XXX: an error occured. should we restart dev? */
+	}
+}
+
 int
 dev_start(const char *plugin)
 {
 
 	fd = dev_start1(plugin);
 	if (fd != -1) {
-		if (eloop_event_add(fd, dev->handle_data, NULL) == -1) {
+		if (eloop_event_add(fd, dev_handle_data, NULL) == -1) {
 			syslog(LOG_ERR, "%s: eloop_event_add: %m", __func__);
 			dev_stop();
 			return -1;
--- a/dev.h	Thu Sep 12 22:11:04 2013 +0000
+++ b/dev.h	Sat Sep 14 08:50:41 2013 +0000
@@ -32,7 +32,7 @@
 	const char *name;
 	int (*initialized)(const char *);
 	int (*listening)(void);
-	void (*handle_data)(void *);
+	int (*handle_device)(void);
 	int (*start)(void);
 	void (*stop)(void);
 };
--- a/dev/udev.c	Thu Sep 12 22:11:04 2013 +0000
+++ b/dev/udev.c	Sat Sep 14 08:50:41 2013 +0000
@@ -72,16 +72,16 @@
 	return r;
 }
 
-static void
-udev_handle_data(__unused void *arg)
+static int
+udev_handle_device(void)
 {
 	struct udev_device *device;
 	const char *subsystem, *ifname, *action;
 
 	device = udev_monitor_receive_device(monitor);
 	if (device == NULL) {
-		syslog(LOG_DEBUG, "libudev: received NULL device");
-		return;
+		syslog(LOG_ERR, "libudev: received NULL device");
+		return -1;
 	}
 
 	subsystem = udev_device_get_subsystem(device);
@@ -98,6 +98,7 @@
 	}
 
 	udev_device_unref(device);
+	return 1;
 }
 
 static void
@@ -168,7 +169,7 @@
 	dev->name = udev_name;
 	dev->initialized = udev_initialized;
 	dev->listening = udev_listening;
-	dev->handle_data = udev_handle_data;
+	dev->handle_device = udev_handle_device;
 	dev->stop = udev_stop;
 	dev->start = udev_start;