sd-device: do not cache an empty string but clear cache on failre
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 18 Feb 2021 08:13:41 +0000 (17:13 +0900)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Mon, 12 Feb 2024 15:37:49 +0000 (16:37 +0100)
And propagate the original error on write.
Note that some attributes are read-only.

Original: upstream, https://github.com/systemd/systemd/pull/18684
Change-Id: I995f86a156b5e974844e0fec9aabf384302a0c3b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/libsystemd/sd-device/sd-device.c

index f35612f..04696f4 100644 (file)
@@ -1851,21 +1851,9 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
 
         r = write_string_file(path, value, WRITE_STRING_FILE_DISABLE_BUFFER | WRITE_STRING_FILE_NOFOLLOW);
         if (r < 0) {
-                if (r == -ELOOP)
-                        return -EINVAL;
-                if (r == -EISDIR)
-                        return r;
-
-                r = free_and_strdup(&value, "");
-                if (r < 0)
-                        return r;
-
-                r = device_add_sysattr_value(device, sysattr, value);
-                if (r < 0)
-                        return r;
-                TAKE_PTR(value);
-
-                return -ENXIO;
+                /* On failure, clear cache entry, as we do not know how it fails. */
+                device_remove_sysattr_value(device, sysattr);
+                return r;
         }
 
         r = device_add_sysattr_value(device, sysattr, value);