static void device_done(Unit *u) { Device *d = DEVICE(u); assert(d); device_unset_sysfs(d); }
static int device_set_sysfs(Device *d, const char *sysfs) { Device *first; char *copy; int r; assert(d); if (streq_ptr(d->sysfs, sysfs)) return 0; r = hashmap_ensure_allocated(&UNIT(d)->manager->devices_by_sysfs, &string_hash_ops); if (r < 0) return r; copy = strdup(sysfs); if (!copy) return -ENOMEM; device_unset_sysfs(d); first = hashmap_get(UNIT(d)->manager->devices_by_sysfs, sysfs); LIST_PREPEND(same_sysfs, first, d); r = hashmap_replace(UNIT(d)->manager->devices_by_sysfs, copy, first); if (r < 0) { LIST_REMOVE(same_sysfs, first, d); free(copy); return r; } d->sysfs = copy; return 0; }