diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-02-21 07:53:31 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-04-02 15:09:03 +0900 |
commit | 112e6dd106773fd0bd0d32f5452e82857e6b2c03 (patch) | |
tree | 17f2214b3099ca41793c457818a18728fedde9f4 /src/libsystemd | |
parent | 8ab34a49dbf75fd731973359a6f24c212682f479 (diff) | |
download | systemd-112e6dd106773fd0bd0d32f5452e82857e6b2c03.tar.gz |
sd-device-monitor: split passes_filter() into two parts
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-device/device-monitor.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 3948e862a9..d072171beb 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -342,49 +342,62 @@ static sd_device_monitor *device_monitor_free(sd_device_monitor *m) { DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_device_monitor, sd_device_monitor, device_monitor_free); -static int passes_filter(sd_device_monitor *m, sd_device *device) { - const char *tag, *subsystem, *devtype, *s, *d = NULL; +static int check_subsystem_filter(sd_device_monitor *m, sd_device *device) { + const char *s, *subsystem, *d, *devtype = NULL; int r; assert(m); assert(device); if (hashmap_isempty(m->subsystem_filter)) - goto tag; + return true; - r = sd_device_get_subsystem(device, &s); + r = sd_device_get_subsystem(device, &subsystem); if (r < 0) return r; - r = sd_device_get_devtype(device, &d); + r = sd_device_get_devtype(device, &devtype); if (r < 0 && r != -ENOENT) return r; - HASHMAP_FOREACH_KEY(devtype, subsystem, m->subsystem_filter) { + HASHMAP_FOREACH_KEY(d, s, m->subsystem_filter) { if (!streq(s, subsystem)) continue; - if (!devtype) - goto tag; + if (!d || streq_ptr(d, devtype)) + return true; + } - if (!d) - continue; + return false; +} - if (streq(d, devtype)) - goto tag; - } +static bool check_tag_filter(sd_device_monitor *m, sd_device *device) { + const char *tag; - return 0; + assert(m); + assert(device); -tag: if (set_isempty(m->tag_filter)) - return 1; + return true; SET_FOREACH(tag, m->tag_filter) if (sd_device_has_tag(device, tag) > 0) - return 1; + return true; - return 0; + return false; +} + +static int passes_filter(sd_device_monitor *m, sd_device *device) { + int r; + + assert(m); + assert(device); + + r = check_subsystem_filter(m, device); + if (r <= 0) + return r; + + return check_tag_filter(m, device); } int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) { |