[PATCH libevdev 1/2] uinput: use the UI_GET_SYSNAME ioctl if available

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Jun 19 17:02:17 PDT 2014


On Thu, Jun 19, 2014 at 7:26 PM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  libevdev/libevdev-uinput.c | 12 ++++++++++--
>  libevdev/libevdev-uinput.h | 17 +++++++----------
>  2 files changed, 17 insertions(+), 12 deletions(-)
>
> diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
> index e0ae31e..f8607d1 100644
> --- a/libevdev/libevdev-uinput.c
> +++ b/libevdev/libevdev-uinput.c
> @@ -198,8 +198,17 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev)
>  {
>         struct dirent **namelist;
>         int ndev, i;
> +       int rc;
> +       char buf[sizeof(SYS_INPUT_DIR) + 64] = SYS_INPUT_DIR;
>
> -       /* FIXME: use new ioctl() here once kernel supports it */
> +       rc = ioctl(uinput_dev->fd,
> +                  UI_GET_SYSNAME(sizeof(buf) - strlen(SYS_INPUT_DIR)),
> +                  &buf[strlen(SYS_INPUT_DIR)]);
> +       if (rc != -1) {
> +               uinput_dev->syspath = strdup(buf);
> +               uinput_dev->devnode = fetch_device_node(buf);
> +               return 0;
> +       }
>
>         ndev = scandir(SYS_INPUT_DIR, &namelist, is_input_device, alphasort);
>         if (ndev <= 0)
> @@ -207,7 +216,6 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev)
>
>         for (i = 0; i < ndev; i++) {
>                 int fd, len;
> -               char buf[sizeof(SYS_INPUT_DIR) + 64];
>                 struct stat st;
>
>                 strcpy(buf, SYS_INPUT_DIR);
> diff --git a/libevdev/libevdev-uinput.h b/libevdev/libevdev-uinput.h
> index fa3eae7..f789711 100644
> --- a/libevdev/libevdev-uinput.h
> +++ b/libevdev/libevdev-uinput.h
> @@ -176,17 +176,14 @@ int libevdev_uinput_get_fd(const struct libevdev_uinput *uinput_dev);
>  /**
>   * @ingroup uinput
>   *
> - * Return the syspath representing this uinput device.
> - * At the time of writing, the uinput kernel device does not
> - * provide a way to get the syspath directly through uinput so libevdev must guess.
> - * In some cases libevdev is unable to derive the syspath. If the running kernel
> - * supports the UI_GET_SYSNAME ioctl, the syspath is retrieved through that and will
> - * be reliable and not be NULL. The UI_GET_SYSNAME ioctl is currently
> - * scheduled for 3.15.
> + * Return the syspath representing this uinput device. If the UI_GET_SYSNAME
> + * ioctl not available, libevdev makes an educated guess.
> + * The UI_GET_SYSNAME ioctl is available since Linux 3.15.
>   *
> - * @note This function may return NULL. libevdev currently uses ctime and
> - * the device name to guess devices. To avoid false positives, wait at least
> - * wait at least 1.5s between creating devices that have the same name.
> + * @note This function may return NULL if UI_GET_SYSNAME is not available.
> + * libevdev currently uses ctime and the device name to guess devices. To

Nitpick: "libevdev _therefore_ uses ctime and the device name to guess devices."

The currently is IMO misleading.

Other than that:
Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

Cheers,
Benjamin

> + * avoid false positives, wait at least wait at least 1.5s between creating
> + * devices that have the same name.
>   * @param uinput_dev A previously created uinput device.
>   * @return The syspath for this device, including the preceding /sys
>   *
> --
> 1.9.3
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools


More information about the Input-tools mailing list