[libinput] How can I prevent duplicated device?

Peter Hutterer peter.hutterer at who-t.net
Tue Aug 23 06:15:35 UTC 2016


On Tue, Aug 23, 2016 at 02:25:15PM +0900, ������ wrote:
> Hello, guys.
> 
> I have a one question about the libinput API.
> I want to share your opinions about duplicated device added events via udev.
> 
> Suppose to duplicated device add events(about a same device) are occurred.
> Currently libinput opens two fd about a same event node.
> So that I have a question that this process is right or a bug.
> 
> I thought several ways why you doesn't process this duplicated device
> added events.
> 
> First, duplicated device add events are abnormal events so that
> we do not concerned about this situation.
> 
> But sometimes we need to prevent these abnormal situation.

if we get the same device twice from udev that's a bug in udev and needs to
be fixed there. trying to work around this and similar bugs in libinput
is just an endless can of worms. how do you even get the same device twice?

Cheers,
   Peter

> If it is valid to prevent duplicated device add events, which points is
> good to add code.
> 
> First method is to use open_restrict interface.
> It means that the libinput allow duplicated device add events and 
> if user want to prevent it, do that in open_restrict interface.
> 
> But I regard as a burden to do that in the open_restrict(),
> if it is right policy to prevent duplicated device add events.
> So I added prevent code in the evdev_device_create() function.
> Please refer attached patch file.(I copied this code below of email)
> 
> Please let me know your opinions about duplicated device add events.
> I'll waiting your opinions and it is very helpful to me.
> 
> Thanks and regards,
> JengHyun Kang.
> 
> From 38e6005d01035f535e79207c856f4b4c80cb788b Mon Sep 17 00:00:00 2001
> From: JengHyun Kang <jhyuni.kang at samsung.com>
> Date: Tue, 23 Aug 2016 14:18:06 +0900
> Subject: [PATCH] evdev: Do not open the already opened device
> 
> ---
>  src/evdev.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/src/evdev.c b/src/evdev.c
> index f798e8e..35e3cec 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -2529,6 +2529,16 @@ evdev_device_create(struct libinput_seat *seat,
>  	int fd;
>  	int unhandled_device = 0;
>  	const char *devnode = udev_device_get_devnode(udev_device);
> +	struct libinput_device *dev;
> +
> +	list_for_each(dev, &seat->devices_list, link) {
> +		struct evdev_device *d = (struct evdev_device*)dev;
> +		if (streq(devnode, udev_device_get_devnode(d-
> >udev_device))) {
> +			log_info(libinput,
> +				"%s device is already opened\n", d-
> >devname);
> +			goto err;
> +		}
> +	}
>  
>  	/* Use non-blocking mode so that we can loop on read on
>  	 * evdev_device_data() until all events on the fd are
> -- 
> 1.9.1




More information about the wayland-devel mailing list