From 83e446225d3a71f4aea8691d28c5ced763afb360 Mon Sep 17 00:00:00 2001 From: Niclas Zeising Date: Thu, 13 Aug 2020 12:01:35 +0200 Subject: [PATCH] uinput: Implement FreeBSD fetch_syspath_and_devnode() Implement a FreeBSD version of fetch_syspath_and_devnode(). FreeBSD does not have sysfs, so instead fetch the device node directly as as this matches with what is returned by the UI_GET_SYSNAME ioctl(). Since there is no sysfs, libevdev_uinput.syspath will always be set to NULL. If the ioctl fail, return -1 from fetch_syspath_and_devnode(), since there is no other way to figure out the device node path. Signed-off-by: Niclas Zeising --- libevdev/libevdev-uinput.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c index 7bbff44..a7a8ad3 100644 --- a/libevdev/libevdev-uinput.c +++ b/libevdev/libevdev-uinput.c @@ -180,6 +180,35 @@ libevdev_uinput_get_fd(const struct libevdev_uinput *uinput_dev) return uinput_dev->fd; } +#ifdef __FreeBSD__ +/* + * FreeBSD does not have anything similar to sysfs. + * Set libevdev_uinput->syspath to NULL unconditionally. + * Look up the device nodes directly instead of via sysfs, as this matches what + * is returned by the UI_GET_SYSNAME ioctl() on FreeBSD. + */ +static int +fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev) +{ +#define DEV_INPUT_DIR "/dev/input/" + int rc; + char buf[sizeof(DEV_INPUT_DIR) + 64] = DEV_INPUT_DIR; + + rc = ioctl(uinput_dev->fd, + UI_GET_SYSNAME(sizeof(buf) - strlen(DEV_INPUT_DIR)), + &buf[strlen(DEV_INPUT_DIR)]); + if (rc == -1) + return -1; + + uinput_dev->syspath = NULL; + uinput_dev->devnode = strdup(buf); + + return 0; +#undef DEV_INPUT_DIR +} + +#else /* !__FreeBSD__ */ + static int is_event_device(const struct dirent *dent) { return strncmp("event", dent->d_name, 5) == 0; } @@ -291,6 +320,7 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev) return uinput_dev->devnode ? 0 : -1; #undef SYS_INPUT_DIR } +#endif /* __FreeBSD__*/ static int uinput_create_write(const struct libevdev *dev, int fd) -- 2.7.4