]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: make device_set_syspath() clear sysname and sysnum
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 9 Jan 2023 05:00:09 +0000 (14:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 9 Jan 2023 05:00:20 +0000 (14:00 +0900)
Otherwise, when a new syspath is assigned to the sd-device object,
sd_device_get_sysname() or _sysnum() will provide an outdated device
name or number.

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

index 7cda48c4cafb8ef0bcaf9e655d4344782eb86213..9553938931482df90450f7a86204024fea91e5f0 100644 (file)
@@ -645,10 +645,6 @@ int device_rename(sd_device *device, const char *name) {
         if (r < 0)
                 return r;
 
-        /* Here, only clear the sysname and sysnum. They will be set when requested. */
-        device->sysnum = NULL;
-        device->sysname = mfree(device->sysname);
-
         r = sd_device_get_property_value(device, "INTERFACE", &interface);
         if (r == -ENOENT)
                 return 0;
index 2fcdce7bac9f48a6f7e07debcdce080e4257c5c0..f8a320dddaad529a1864bfcedade2e6ebc5d6ab2 100644 (file)
@@ -249,6 +249,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
 
         free_and_replace(device->syspath, syspath);
         device->devpath = devpath;
+
+        /* Unset sysname and sysnum, they will be assigned when requested. */
+        device->sysnum = NULL;
+        device->sysname = mfree(device->sysname);
         return 0;
 }