]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: do not use ::subsystem member directly
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Jun 2021 07:29:59 +0000 (16:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Jun 2021 20:59:03 +0000 (05:59 +0900)
The value is set dynamically when sd_device_get_subsystem() is called
first time.

Fixes the following issue:
```
$ build/udevadm test /sys/class/block/dm-1
...
Assertion '_subsystem' failed at src/libsystemd/sd-device/sd-device.c:767, function device_set_subsystem(). Aborting.
Program received signal SIGABRT, Aborted.
```

src/libsystemd/sd-device/device-private.c

index 09ef87f84ccd5b97440cc176721972904e814862..3ede43f377586a07323400a398bc91e3cef28eef 100644 (file)
@@ -743,6 +743,7 @@ int device_rename(sd_device *device, const char *name) {
 
 int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
         _cleanup_(sd_device_unrefp) sd_device *ret = NULL;
+        const char *subsystem;
         int r;
 
         assert(old_device);
@@ -756,9 +757,12 @@ int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
         if (r < 0)
                 return r;
 
-        r = device_set_subsystem(ret, old_device->subsystem);
-        if (r < 0)
-                return r;
+        if (sd_device_get_subsystem(old_device, &subsystem) >= 0) {
+                r = device_set_subsystem(ret, subsystem);
+                if (r < 0)
+                        return r;
+        } else
+                ret->subsystem_set = true;
 
         ret->devnum = old_device->devnum;