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 <zeising@daemonic.se>
This commit is contained in:
Niclas Zeising 2020-08-13 12:01:35 +02:00
parent 153d8d0a5a
commit 83e446225d

View 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)