From e05a0cd92cbdad70791bce4e39f87d66f2acdbcd Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 15 Oct 2013 14:29:56 +0200 Subject: [PATCH] evdev: release devices on read() error If read() fails without EAGAIN/EINTR, the device is very likely dead. However, we must not remove the device as it might be muted/revoked. So we simply remove the event-source to avoid polling the device and simply wait for the udev-remove signal now. Note that we cannot call evdev_device_destroy() as the caller created the FD and might need custom code to close it (like weston_launcher_close()). --- src/evdev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/evdev.c b/src/evdev.c index edea3968..7397ea1d 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -22,6 +22,7 @@ #include "config.h" +#include #include #include #include @@ -414,7 +415,13 @@ evdev_device_data(int fd, uint32_t mask, void *data) len = read(fd, &ev, sizeof ev); if (len < 0 || len % sizeof ev[0] != 0) { - /* FIXME: call evdev_device_destroy when errno is ENODEV. */ + if (len < 0 && errno != EAGAIN && errno != EINTR) { + weston_log("device %s died\n", + device->devnode); + wl_event_source_remove(device->source); + device->source = NULL; + } + return 1; }