diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-09-11 13:25:21 +0200 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-09-13 08:46:04 -0400 |
commit | ffdc02f45bcc973249406b2c9bd996f8b27fa2a5 (patch) | |
tree | 5a61a2008512269266b5837b1ea228608a020aa4 /src/libudev | |
parent | 0dc651610248c873e584cbe8afb9495241cdb622 (diff) |
udev: allow removing tags via TAG-="foobar"
This extends the udev parser to support OP_REMOVE (-=) and adds support
for TAG-= to remove previously set tags. We don't fail if the tag didn't
exist.
This is pretty handy if we ship default rules for seat-assignments and
users want to exclude specific devices from that. They can easily add
rules that drop any automatically added "seat" tags again.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev')
-rw-r--r-- | src/libudev/libudev-device.c | 21 | ||||
-rw-r--r-- | src/libudev/libudev-private.h | 1 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index f26a4c44b5..d61a2ad8f4 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -1732,9 +1732,14 @@ void udev_device_set_is_initialized(struct udev_device *udev_device) udev_device->is_initialized = true; } +static bool is_valid_tag(const char *tag) +{ + return !strchr(tag, ':') && !strchr(tag, ' '); +} + int udev_device_add_tag(struct udev_device *udev_device, const char *tag) { - if (strchr(tag, ':') != NULL || strchr(tag, ' ') != NULL) + if (!is_valid_tag(tag)) return -EINVAL; udev_device->tags_uptodate = false; if (udev_list_entry_add(&udev_device->tags_list, tag, NULL) != NULL) @@ -1742,6 +1747,20 @@ int udev_device_add_tag(struct udev_device *udev_device, const char *tag) return -ENOMEM; } +void udev_device_remove_tag(struct udev_device *udev_device, const char *tag) +{ + struct udev_list_entry *e; + + if (!is_valid_tag(tag)) + return; + e = udev_list_get_entry(&udev_device->tags_list); + e = udev_list_entry_get_by_name(e, tag); + if (e) { + udev_device->tags_uptodate = false; + udev_list_entry_delete(e); + } +} + void udev_device_cleanup_tags_list(struct udev_device *udev_device) { udev_device->tags_uptodate = false; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 2ad74c0d9c..53730a4baf 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -74,6 +74,7 @@ const char *udev_device_get_devpath_old(struct udev_device *udev_device); const char *udev_device_get_id_filename(struct udev_device *udev_device); void udev_device_set_is_initialized(struct udev_device *udev_device); int udev_device_add_tag(struct udev_device *udev_device, const char *tag); +void udev_device_remove_tag(struct udev_device *udev_device, const char *tag); void udev_device_cleanup_tags_list(struct udev_device *udev_device); usec_t udev_device_get_usec_initialized(struct udev_device *udev_device); void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized); |