Allow dev to recieve errors from managers handle_device.

This commit is contained in:
Roy Marples 2013-09-14 08:50:41 +00:00
parent 4b21a1f7c9
commit 36d293b12a
3 changed files with 17 additions and 7 deletions

11
dev.c
View File

@ -143,13 +143,22 @@ dev_start1(const char *plugin)
return r; return r;
} }
static void
dev_handle_data(__unused void *arg)
{
if (dev->handle_device() == -1) {
/* XXX: an error occured. should we restart dev? */
}
}
int int
dev_start(const char *plugin) dev_start(const char *plugin)
{ {
fd = dev_start1(plugin); fd = dev_start1(plugin);
if (fd != -1) { 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__); syslog(LOG_ERR, "%s: eloop_event_add: %m", __func__);
dev_stop(); dev_stop();
return -1; return -1;

2
dev.h
View File

@ -32,7 +32,7 @@ struct dev {
const char *name; const char *name;
int (*initialized)(const char *); int (*initialized)(const char *);
int (*listening)(void); int (*listening)(void);
void (*handle_data)(void *); int (*handle_device)(void);
int (*start)(void); int (*start)(void);
void (*stop)(void); void (*stop)(void);
}; };

View File

@ -72,16 +72,16 @@ udev_initialized(const char *ifname)
return r; return r;
} }
static void static int
udev_handle_data(__unused void *arg) udev_handle_device(void)
{ {
struct udev_device *device; struct udev_device *device;
const char *subsystem, *ifname, *action; const char *subsystem, *ifname, *action;
device = udev_monitor_receive_device(monitor); device = udev_monitor_receive_device(monitor);
if (device == NULL) { if (device == NULL) {
syslog(LOG_DEBUG, "libudev: received NULL device"); syslog(LOG_ERR, "libudev: received NULL device");
return; return -1;
} }
subsystem = udev_device_get_subsystem(device); subsystem = udev_device_get_subsystem(device);
@ -98,6 +98,7 @@ udev_handle_data(__unused void *arg)
} }
udev_device_unref(device); udev_device_unref(device);
return 1;
} }
static void static void
@ -168,7 +169,7 @@ dev_init(struct dev *dev, const struct dev_dhcpcd *dev_dhcpcd)
dev->name = udev_name; dev->name = udev_name;
dev->initialized = udev_initialized; dev->initialized = udev_initialized;
dev->listening = udev_listening; dev->listening = udev_listening;
dev->handle_data = udev_handle_data; dev->handle_device = udev_handle_device;
dev->stop = udev_stop; dev->stop = udev_stop;
dev->start = udev_start; dev->start = udev_start;