From: Yu Watanabe Date: Sat, 20 Feb 2021 22:53:31 +0000 (+0900) Subject: sd-device-monitor: split passes_filter() into two parts X-Git-Tag: v249-rc1~483^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=112e6dd106773fd0bd0d32f5452e82857e6b2c03;p=thirdparty%2Fsystemd.git sd-device-monitor: split passes_filter() into two parts --- diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 3948e862a9f..d072171bebd 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) {