Bug 1302359 - udev_device_get_sysattr_value () does not consistently return contents of sys attribute file
udev_device_get_sysattr_value () does not consistently return contents of sys...
Status: NEW
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: systemd-maint
Depends On:
  Show dependency treegraph
Reported: 2016-01-27 10:28 EST by mulhern
Modified: 2018-02-14 18:06 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Simple reproducer that works on my machine for this particular boot. (1.60 KB, text/plain)
2016-01-27 10:28 EST, mulhern
no flags Details

  None (edit)
Description mulhern 2016-01-27 10:28:08 EST
Created attachment 1118822 [details]
Simple reproducer that works on my machine for this particular boot.

Description of problem:

udev_device_get_sysattr_value() is defined to return the contents of a sys attr file. In some cases, it doesn't.

Version-Release number of selected component (if applicable):


How reproducible:

Consistently, for the particular devices and attributes chosen. It is not clear what it is about the particular attribute file that causes the behavior.

Steps to Reproduce:
1. My reproducer contains two examples of devices that behave differently.
2. Run the reproducer. Note that both devices have vpg_pg83 attribute files that are non-empty (wc claims that both contain characters, and cat echos random glyphs to the terminal in both cases).
3. Note that in one case, the result of calling udev_deivce_get_sysattr_value is the empty string and that in the other case it is a non-empty string.

Actual results:

Inconsistent behavior in reading non-empty vpg_pg83 attribute file for different devices.

Expected results:

Well-documented consistency.

Additional info:

I think this also affects the behavior of udevadm info --attribute-walk for these devices. AFAIU, udevadm is defined not to show binary attributes, restricting itself to those that are matched in udev rules. For the device where the method returns a non-empty string, udevadm does not show a corresponding vpd_pg83 attribute. For the device where the function mistakenly returns an empty string, udevadm does show the attribute, apparently interpreting it, since empty, as matchable text.
Comment 2 mulhern 2016-01-27 11:48:26 EST
It looks like the value stops at the first 0x00 character. 
In my reproducer, with the device that returns a non-empty string, only part of the data is returned, since the null character occurs after two characters. With the device that returns an empty string, the null character is the first character, so the empty string is returned.
Comment 3 Gris Ge 2017-02-16 08:54:40 EST

IMHO, this is not a bug, by definition of udev_device_get_sysattr_value(), it returns a string, so truncate after first \0 found is reasonable. 
In case of reading file like vpd83, you could manually read it or ask udev team to create new function like 
'udev_device_get_sysattr_value_raw(struct udev_device *udev_device, const char *sysattr, uint8_t *buff, size_t buff_max_size))'.
Comment 4 Gris Ge 2017-02-16 08:56:20 EST
Sorry, I missed the part you are asking for consistency. Please ignore my previous comment.

Note You need to log in before you can comment on or make changes to this bug.