Red Hat Bugzilla – Bug 1265315
Some "available" attributes returned by udev_device_get_sysattr have no value
Last modified: 2015-11-10 08:06:56 EST
Created attachment 1075902 [details]
Simple test file illustrating an example device
Description of problem:
udev_device_get_sysattr_list_entry returns a list of attribute, value pairs.
The values are NULL, the attributes are said to be "available".
From the docs:
Retrieve the list of available sysattrs, with value being empty; This just return all available sysfs attributes for a particular device without reading their values.
I dunno what "available" is supposed to mean, but if these attributes are
further looked up by "udev_device_get_sysattr_value" they may have no value,
i.e., this method may return NULL. (This is not the same as having a value
like the empty string, which fits the specification just fine.)
Version-Release number of selected component (if applicable):
Consistently, for a given device.
Steps to Reproduce:
1. Loop over all devices returned by udevadm.
2. List the attributes using udev_device_get_sysattr_list_entry().
3. Look up the listed attributes using udev_device_get_sysattr_value(). Observe that some of these attributes are NULL.
Some "available" attributes have no values. Generally speaking, these attributes seem to be symlinks to directories. It is not true that all attributes that correspond to symlinks to directories have no value, only some.
"Available" attributes should have a value or documentation should define clearly that "available" means fits some criteria which does not necessarily include actually having a value.
It is normal to think of attribute name/value pairs as being like keys in a map.
If they are not, that is, if a key can simultaneously be in the map and not be
in the map, that should get better documentation then by the single word "available".
Also, in documentation, the ';' is followed by a capital letter, should be lowercase.
Output of new.c on my Fedora desktop. This is just an example, similar things
happen on my RHEL 7.2 box.
[mulhern@localhost reproducers]$ ./a.out
Correct behavior, values are not obtained.
Incorrect behavior; physical_node should have a value.
correct behavior, value of non-existant attribute is null.
Should be like the first.
Created attachment 1076292 [details]
Simple python script that reports attributes that are listed but have no value
The attached file printed SURPRISE a few times on both systems, indicating that some of the attributes with no value were not symlinked directories. What characteristics they do have I do not know.
Given that I have an answer to my question in bz#1267584 this bug can not be said to block it. The only outstanding issue really is that these methods should be documented better, to avoid the same confusion arising for someone else in the future.
PR at: https://github.com/systemd/systemd/pull/1818.
Probably a thorough understanding of the architecture and underlying assumptions of this component would allow a user to infer the most important consequences of the relations between the methods involved from the existing documentation.