summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-08-06 04:17:51 +0200
committerLennart Poettering <lennart@poettering.net>2010-08-06 04:17:51 +0200
commitee6cb28869d94f25a79f2c7cd29f1574c590036c (patch)
tree55b9f16d3e2e99b3dd37dcf097341ca3d130c17a /src/device.c
parent3c661fadd5e0d74acc7596024db31be00c53b448 (diff)
device: properly handle devices that are referenced before they show up
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/device.c b/src/device.c
index 46b3ed3dff..a196a982a0 100644
--- a/src/device.c
+++ b/src/device.c
@@ -195,7 +195,6 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
}
if (!u) {
- Device *first;
delete = true;
if (!(u = unit_new(m)))
@@ -204,13 +203,22 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
if ((r = device_add_escaped_name(u, path)) < 0)
goto fail;
+ unit_add_to_load_queue(u);
+ } else
+ delete = false;
+
+ /* If this was created via some dependency and has not
+ * actually been seen yet ->sysfs will not be
+ * initialized. Hence initialize it if necessary. */
+
+ if (!DEVICE(u)->sysfs) {
+ Device *first;
+
if (!(DEVICE(u)->sysfs = strdup(sysfs))) {
r = -ENOMEM;
goto fail;
}
- unit_add_to_load_queue(u);
-
if (!m->devices_by_sysfs)
if (!(m->devices_by_sysfs = hashmap_new(string_hash_func, string_compare_func))) {
r = -ENOMEM;
@@ -222,9 +230,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
if ((r = hashmap_replace(m->devices_by_sysfs, DEVICE(u)->sysfs, first)) < 0)
goto fail;
-
- } else
- delete = false;
+ }
if ((model = udev_device_get_property_value(dev, "ID_MODEL_FROM_DATABASE")) ||
(model = udev_device_get_property_value(dev, "ID_MODEL"))) {