]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: also show write-only attributes 21763/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 13 Dec 2021 21:25:03 +0000 (06:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Dec 2021 12:50:02 +0000 (21:50 +0900)
src/udev/udevadm-info.c

index 84f7794e86fb7b9ae5a0b0978d4d35b8b5da23f1..1c5cec86b85419433b5b1517d84a82c4d05a6265 100644 (file)
@@ -73,6 +73,7 @@ static int print_all_attributes(sd_device *device, bool is_parent) {
         _cleanup_free_ SysAttr *sysattrs = NULL;
         const char *name, *value;
         size_t n_items = 0;
+        int r;
 
         value = NULL;
         (void) sd_device_get_devpath(device, &value);
@@ -96,18 +97,22 @@ static int print_all_attributes(sd_device *device, bool is_parent) {
                 if (skip_attribute(name))
                         continue;
 
-                if (sd_device_get_sysattr_value(device, name, &value) < 0)
-                        continue;
+                r = sd_device_get_sysattr_value(device, name, &value);
+                if (r >= 0) {
+                        /* skip any values that look like a path */
+                        if (value[0] == '/')
+                                continue;
 
-                /* skip any values that look like a path */
-                if (value[0] == '/')
-                        continue;
+                        /* skip nonprintable attributes */
+                        len = strlen(value);
+                        while (len > 0 && isprint((unsigned char) value[len-1]))
+                                len--;
+                        if (len > 0)
+                                continue;
 
-                /* skip nonprintable attributes */
-                len = strlen(value);
-                while (len > 0 && isprint((unsigned char) value[len-1]))
-                        len--;
-                if (len > 0)
+                } else if (r == -EPERM)
+                        value = "(write-only)";
+                else
                         continue;
 
                 if (!GREEDY_REALLOC(sysattrs, n_items + 1))