uinput: Implement FreeBSD fetch_syspath_and_devnode()
authorNiclas Zeising <zeising@daemonic.se>
Thu, 13 Aug 2020 10:01:35 +0000 (12:01 +0200)
committerNiclas Zeising <zeising@daemonic.se>
Fri, 14 Aug 2020 15:50:56 +0000 (17:50 +0200)
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 <zeising@daemonic.se>
libevdev/libevdev-uinput.c

index 7bbff44..a7a8ad3 100644 (file)
@@ -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)