From ab218d0bdb11e70878907e1139c90b8e48f51e2d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 14 Dec 2021 06:24:24 +0900 Subject: [PATCH 1/2] sd-device: make FOREACH_DEVICE_SYSATTR() also list write-only attributes Closes #10102. --- src/libsystemd/sd-device/sd-device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index e594d5fbe4..8b6e1ddd69 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1812,7 +1812,7 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd if (lstat(path, &statbuf) != 0) continue; - if (!(statbuf.st_mode & S_IRUSR)) + if ((statbuf.st_mode & (S_IRUSR | S_IWUSR)) == 0) continue; r = set_put_strdup(&device->sysattrs, p ?: dent->d_name); From 3a90bef55a5a71a03629a762470b0f9014cd8453 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 14 Dec 2021 06:25:03 +0900 Subject: [PATCH 2/2] udevadm: also show write-only attributes --- src/udev/udevadm-info.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 84f7794e86..1c5cec86b8 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -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))