X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fdevice.c;h=734d3f32e10a06b8a3f21c1ea770cef0c194aeff;hb=a6b26d9011de60e1c41f51e8d2aab1d2f7bbf0f5;hp=f4c59b3a510de5de20511d67667740d52029bb62;hpb=b0193f1c1f1540bfccbdca02df82669b9308e4e2;p=elogind.git diff --git a/src/core/device.c b/src/core/device.c index f4c59b3a5..734d3f32e 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -92,10 +92,10 @@ static void device_set_state(Device *d, DeviceState state) { d->state = state; if (state != old_state) - log_debug("%s changed %s -> %s", - UNIT(d)->id, - device_state_to_string(old_state), - device_state_to_string(state)); + log_debug_unit(UNIT(d)->id, + "%s changed %s -> %s", UNIT(d)->id, + device_state_to_string(old_state), + device_state_to_string(state)); unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state], true); } @@ -251,30 +251,46 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p * interpret for the main object */ const char *wants, *alias; - if ((alias = udev_device_get_property_value(dev, "SYSTEMD_ALIAS"))) { - if (!is_path(alias)) - log_warning("SYSTEMD_ALIAS for %s is not a path, ignoring: %s", sysfs, alias); - else { - if ((r = device_add_escaped_name(u, alias)) < 0) + alias = udev_device_get_property_value(dev, "SYSTEMD_ALIAS"); + if (alias) { + char *state, *w; + size_t l; + + FOREACH_WORD_QUOTED(w, l, alias, state) { + char *e; + + e = strndup(w, l); + if (!e) { + r = -ENOMEM; goto fail; + } + + if (!is_path(e)) { + log_warning("SYSTEMD_ALIAS for %s is not a path, ignoring: %s", sysfs, e); + free(e); + } else { + device_update_unit(m, dev, e, false); + free(e); + } } } - if ((wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS"))) { + wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS"); + if (wants) { char *state, *w; size_t l; FOREACH_WORD_QUOTED(w, l, wants, state) { char *e; - if (!(e = strndup(w, l))) { + e = strndup(w, l); + if (!e) { r = -ENOMEM; goto fail; } r = unit_add_dependency_by_name(u, UNIT_WANTS, e, NULL, true); free(e); - if (r < 0) goto fail; } @@ -296,6 +312,7 @@ fail: static int device_process_new_device(Manager *m, struct udev_device *dev, bool update_state) { const char *sysfs, *dn; struct udev_list_entry *item = NULL, *first = NULL; + int r; assert(m); @@ -303,7 +320,9 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u return -ENOMEM; /* Add the main unit named after the sysfs path */ - device_update_unit(m, dev, sysfs, true); + r = device_update_unit(m, dev, sysfs, true); + if (r < 0) + return r; /* Add an additional unit for the device node */ if ((dn = udev_device_get_devnode(dev))) @@ -461,7 +480,6 @@ static void device_shutdown(Manager *m) { } static int device_enumerate(Manager *m) { - struct epoll_event ev; int r; struct udev_enumerate *e = NULL; struct udev_list_entry *item = NULL, *first = NULL; @@ -469,6 +487,8 @@ static int device_enumerate(Manager *m) { assert(m); if (!m->udev) { + struct epoll_event ev; + if (!(m->udev = udev_new())) return -ENOMEM; @@ -587,7 +607,6 @@ static const char* const device_state_table[_DEVICE_STATE_MAX] = { DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState); const UnitVTable device_vtable = { - .suffix = ".device", .object_size = sizeof(Device), .sections = "Unit\0"