From 17d66153b061ef8e587fc9e1e96f34d8fc4ce986 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 25 Sep 2015 15:57:14 +0200 Subject: [PATCH] ratbagd: ignore anything but event devices We are only interested in evdev, so ignore anything but input-event devices. Signed-off-by: David Herrmann --- src/ratbagd.c | 2 +- src/shared-macro.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ratbagd.c b/src/ratbagd.c index 69e423a4..e9efc681 100644 --- a/src/ratbagd.c +++ b/src/ratbagd.c @@ -58,7 +58,7 @@ static void ratbagd_process_device(struct ratbagd *ctx, */ name = udev_device_get_sysname(udevice); - if (!name) + if (!name || !startswith(name, "event")) return; device = ratbagd_find_device(ctx, name); diff --git a/src/shared-macro.h b/src/shared-macro.h index 56fa7d10..05ec2f3b 100644 --- a/src/shared-macro.h +++ b/src/shared-macro.h @@ -185,6 +185,25 @@ static inline bool streq_ptr(const char *a, const char *b) return (a && b) ? streq(a, b) : (!a && !b); } +/* + * startswith() - test prefix of a string + * @s: string to test + * @prefix: prefix to test for + * + * This returns a pointer to the first character in @s that follows @prefix. If + * @s does not start with @prefix, NULL is returned. + */ +static inline char *startswith(const char *s, const char *prefix) +{ + size_t l; + + l = strlen(prefix); + if (strncmp(s, prefix, l) == 0) + return (char*) s + l; + + return NULL; +} + /* * now() - returns current time in nano-seconds * @clock: clock to use