eudev-project / eudev

Repository for eudev development
GNU General Public License v2.0
523 stars 147 forks source link

Properly handle empty tag list #171

Closed kempniu closed 5 years ago

kempniu commented 5 years ago

This PR attempts to fix a bug which makes it impossible to remove the last existing tag for a device.

Consider the power-switch tag. elogind ships with a file called 70-power-switch.rules which applies that tag to certain devices. Try removing it e.g. for the ACPI Power Button device by creating an appropriately numbered rule file (e.g. /etc/udev/rules.d/75-remove-power-switch.rules) with the following contents:

SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_KEY}=="1", TAG-="power-switch"

This will not remove the power-switch tag for the device:

$ udevadm test "/sys/$(udevadm info -q path /dev/input/event1)" 2>&1 | grep TAGS
TAGS=:power-switch

If you add any other tag to the tag list for the same device, e.g. by making the aforementioned rule file look like this:

SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_KEY}=="1", TAG-="power-switch"
SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_KEY}=="1", TAG+="foo"

the power-switch tag will be removed correctly:

$ udevadm test "/sys/$(udevadm info -q path /dev/input/event1)" 2>&1 | grep TAGS
TAGS=:foo:

The reason for this behavior is that udev_device_get_properties_list_entry() only updates the TAGS property if the tag list is non-empty.

I believe this is an upstream bug which was fixed in v220 as a side effect of commits 57fa1d094cd2c5ac68970526ad0a0754c548e75d and f4ac4d1a82e2c468761fffa333323841ad886221. Since eudev did not adopt these changes, the bug remained unfixed.

I was not sure how to sum up all of the above in the commit log message, so please let me know if it should be adjusted.

Hope this helps!

kempniu commented 5 years ago

(AFAICT, Travis GCC build failed due a network error during apt-get update, not a code issue.)

blueness commented 5 years ago

Thanks, this is a good catch. I'll test later and commit if okay.

blueness commented 5 years ago

pushed. thanks for the contribution.