X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=device.c;h=b00a0f987f6fb227b7192241e9a2d57f30866dc9;hb=10a94420172b33a7472a16b2e829689dbc570cad;hp=39375a4258282110a5878b49147809fc9dbdc639;hpb=6326a423e7d3df2062bf29a4e9710aeecac89411;p=elogind.git diff --git a/device.c b/device.c index 39375a425..b00a0f987 100644 --- a/device.c +++ b/device.c @@ -42,20 +42,29 @@ static void device_done(Unit *u) { Device *d = DEVICE(u); assert(d); + free(d->sysfs); + d->sysfs = NULL; +} + +static void device_init(Unit *u) { + Device *d = DEVICE(u); + + assert(d); + assert(u->meta.load_state == UNIT_STUB); + + d->state = 0; } static void device_set_state(Device *d, DeviceState state) { DeviceState old_state; assert(d); - if (state == d->state) - return; - old_state = d->state; d->state = state; - log_debug("%s changed %s → %s", unit_id(UNIT(d)), state_string_table[old_state], state_string_table[state]); + if (state != old_state) + log_debug("%s changed %s → %s", unit_id(UNIT(d)), state_string_table[old_state], state_string_table[state]); unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state]); } @@ -90,6 +99,12 @@ static UnitActiveState device_active_state(Unit *u) { return state_translation_table[DEVICE(u)->state]; } +static const char *device_sub_state_to_string(Unit *u) { + assert(u); + + return state_string_table[DEVICE(u)->state]; +} + static int device_add_escaped_name(Unit *u, const char *dn, bool make_id) { char *e; int r; @@ -231,15 +246,16 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u if ((r = device_add_escaped_name(u, sysfs, true)) < 0) goto fail; + unit_add_to_load_queue(u); + } else + delete = false; + + if (!(DEVICE(u)->sysfs)) if (!(DEVICE(u)->sysfs = strdup(sysfs))) { r = -ENOMEM; goto fail; } - unit_add_to_load_queue(u); - } else - delete = false; - if (dn) if ((r = device_add_escaped_name(u, dn, true)) < 0) goto fail; @@ -460,13 +476,15 @@ fail: const UnitVTable device_vtable = { .suffix = ".device", - .init = unit_load_fragment_and_dropin_optional, + .init = device_init, + .load = unit_load_fragment_and_dropin_optional, .done = device_done, .coldplug = device_coldplug, .dump = device_dump, .active_state = device_active_state, + .sub_state_to_string = device_sub_state_to_string, .enumerate = device_enumerate, .shutdown = device_shutdown