]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 20 Feb 2021 19:30:42 +0000 (04:30 +0900)
And propagate the original error on write.
Note that some attributes are read-only.

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

index cc0220b04e3833556e3e2dd26ef4905350c52ef7..68eabdef1a244b36b17ac32d82527d0e634eb40c 100644 (file)
@@ -1985,21 +1985,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_cache_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_cached_sysattr_value(device, sysattr);
+                return r;
         }
 
         r = device_cache_sysattr_value(device, sysattr, value);