]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
device: make sure to remove all device units sharing the same sysfs path (#6679)
authorFranck Bui <fbui@suse.com>
Wed, 30 Aug 2017 15:16:16 +0000 (17:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 Aug 2017 15:16:16 +0000 (17:16 +0200)
When a device is unplugged all device units sharing the same sysfs path
pointing to that device are supposed to be removed.

However it didn't work since while iterating the device unit list containing
all the relevant units, each unit was removed during each iteration of
LIST_FOREACH. However LIST_FOREACH doesn't support this use case and
LIST_FOREACH_SAFE must be use instead.

src/core/device.c

index 77601c5520bc6e2a69b16c42d7c1ee03dff2a03c..87186f135bf817f15fcd5205980a94f49aa08dd9 100644 (file)
@@ -514,7 +514,7 @@ static void device_update_found_one(Device *d, bool add, DeviceFound found, bool
 }
 
 static int device_update_found_by_sysfs(Manager *m, const char *sysfs, bool add, DeviceFound found, bool now) {
-        Device *d, *l;
+        Device *d, *l, *n;
 
         assert(m);
         assert(sysfs);
@@ -523,7 +523,7 @@ static int device_update_found_by_sysfs(Manager *m, const char *sysfs, bool add,
                 return 0;
 
         l = hashmap_get(m->devices_by_sysfs, sysfs);
-        LIST_FOREACH(same_sysfs, d, l)
+        LIST_FOREACH_SAFE(same_sysfs, d, n, l)
                 device_update_found_one(d, add, found, now);
 
         return 0;