X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fdevice.c;h=39ab29110374058a125e94d064f7991219cf91d0;hb=5632e3743db350a67478acc107d76cdf648a1f99;hp=e67d0a6c2d71e1d2ec83db8e3fcdc854dd2e41e4;hpb=e99e38bbdcca3fe5956823bdb3d38544ccf93221;p=elogind.git diff --git a/src/device.c b/src/device.c index e67d0a6c2..39ab29110 100644 --- a/src/device.c +++ b/src/device.c @@ -32,9 +32,18 @@ static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = { [DEVICE_DEAD] = UNIT_INACTIVE, - [DEVICE_AVAILABLE] = UNIT_ACTIVE + [DEVICE_PLUGGED] = UNIT_ACTIVE }; +static void device_init(Unit *u) { + Device *d = DEVICE(u); + + assert(d); + assert(d->meta.load_state == UNIT_STUB); + + d->meta.job_timeout = DEFAULT_TIMEOUT_USEC; +} + static void device_done(Unit *u) { Device *d = DEVICE(u); @@ -53,7 +62,7 @@ static void device_set_state(Device *d, DeviceState state) { if (state != old_state) log_debug("%s changed %s -> %s", - UNIT(d)->meta.id, + d->meta.id, device_state_to_string(old_state), device_state_to_string(state)); @@ -67,7 +76,7 @@ static int device_coldplug(Unit *u) { assert(d->state == DEVICE_DEAD); if (d->sysfs) - device_set_state(d, DEVICE_AVAILABLE); + device_set_state(d, DEVICE_PLUGGED); return 0; } @@ -144,31 +153,19 @@ static int device_find_escape_name(Manager *m, const char *dn, Unit **_u) { } static int device_process_new_device(Manager *m, struct udev_device *dev, bool update_state) { - const char *dn, *wants, *sysfs, *expose, *model, *alias; + const char *dn, *wants, *sysfs, *model, *alias; Unit *u = NULL; int r; char *w, *state; size_t l; bool delete; struct udev_list_entry *item = NULL, *first = NULL; - int b; assert(m); if (!(sysfs = udev_device_get_syspath(dev))) return -ENOMEM; - if (!(expose = udev_device_get_property_value(dev, "SYSTEMD_EXPOSE"))) - return 0; - - if ((b = parse_boolean(expose)) < 0) { - log_error("Failed to parse SYSTEMD_EXPOSE udev property for device %s: %s", sysfs, expose); - return 0; - } - - if (!b) - return 0; - /* Check whether this entry is even relevant for us. */ dn = udev_device_get_devnode(dev); wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS"); @@ -256,7 +253,7 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u goto fail; if (wants) { - FOREACH_WORD(w, l, wants, state) { + FOREACH_WORD_QUOTED(w, l, wants, state) { char *e; if (!(e = strndup(w, l))) { @@ -264,7 +261,7 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u goto fail; } - r = unit_add_dependency_by_name(u, UNIT_WANTS, NULL, e, true); + r = unit_add_dependency_by_name(u, UNIT_WANTS, e, NULL, true); free(e); if (r < 0) @@ -274,7 +271,7 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u if (update_state) { manager_dispatch_load_queue(u->meta.manager); - device_set_state(DEVICE(u), DEVICE_AVAILABLE); + device_set_state(DEVICE(u), DEVICE_PLUGGED); } unit_add_to_dbus_queue(u); @@ -282,8 +279,12 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u return 0; fail: + + log_warning("Failed to load device unit: %s", strerror(-r)); + if (delete && u) unit_free(u); + return r; } @@ -365,6 +366,11 @@ static int device_enumerate(Manager *m) { goto fail; } + if (udev_monitor_filter_add_match_tag(m->udev_monitor, "systemd") < 0) { + r = -ENOMEM; + goto fail; + } + if (udev_monitor_enable_receiving(m->udev_monitor) < 0) { r = -EIO; goto fail; @@ -385,6 +391,10 @@ static int device_enumerate(Manager *m) { r = -ENOMEM; goto fail; } + if (udev_enumerate_add_match_tag(e, "systemd") < 0) { + r = -EIO; + goto fail; + } if (udev_enumerate_scan_devices(e) < 0) { r = -EIO; @@ -442,7 +452,7 @@ fail: static const char* const device_state_table[_DEVICE_STATE_MAX] = { [DEVICE_DEAD] = "dead", - [DEVICE_AVAILABLE] = "available" + [DEVICE_PLUGGED] = "plugged" }; DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState); @@ -455,6 +465,8 @@ const UnitVTable device_vtable = { .no_snapshots = true, .no_isolate = true, + .init = device_init, + .load = unit_load_fragment_and_dropin_optional, .done = device_done, .coldplug = device_coldplug,