struct evdev_device *
evdev_device_create(struct libinput_seat *seat,
const char *devnode,
- const char *sysname)
+ const char *sysname,
+ const char *syspath)
{
struct libinput *libinput = seat->libinput;
struct evdev_device *device;
device->mtdev = NULL;
device->devnode = strdup(devnode);
device->sysname = strdup(sysname);
+ device->syspath = strdup(syspath);
device->rel.dx = 0;
device->rel.dy = 0;
device->abs.seat_slot = -1;
return 0;
}
+static int
+evdev_device_compare_syspath(struct evdev_device *device, int fd)
+{
+ struct udev *udev = NULL;
+ struct udev_device *udev_device = NULL;
+ const char *syspath;
+ struct stat st;
+ int rc = 1;
+
+ udev = udev_new();
+ if (!udev)
+ goto out;
+
+ if (fstat(fd, &st) < 0)
+ goto out;
+
+ udev_device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
+ if (!device)
+ goto out;
+
+ syspath = udev_device_get_syspath(udev_device);
+ rc = strcmp(syspath, device->syspath);
+out:
+ if (udev_device)
+ udev_device_unref(udev_device);
+ if (udev)
+ udev_unref(udev);
+ return rc;
+}
+
int
evdev_device_resume(struct evdev_device *device)
{
if (device->fd != -1)
return 0;
+ if (device->syspath == NULL)
+ return -ENODEV;
+
fd = open_restricted(libinput, device->devnode, O_RDWR | O_NONBLOCK);
if (fd < 0)
return -errno;
+ if (evdev_device_compare_syspath(device, fd)) {
+ close_restricted(libinput, fd);
+ return -ENODEV;
+ }
+
device->fd = fd;
if (evdev_need_mtdev(device)) {
{
evdev_device_suspend(device);
+ /* A device may be removed while suspended. Free the syspath to
+ * skip re-opening a different device with the same node */
+ free(device->syspath);
+ device->syspath = NULL;
+
list_remove(&device->base.link);
notify_removed_device(&device->base);
free(device->mt.slots);
free(device->devnode);
free(device->sysname);
+ free(device->syspath);
free(device);
}
char *output_name;
char *devnode;
char *sysname;
+ char *syspath;
const char *devname;
int fd;
struct {
struct evdev_device *
evdev_device_create(struct libinput_seat *seat,
const char *devnode,
- const char *sysname);
+ const char *sysname,
+ const char *syspath);
struct evdev_dispatch *
evdev_touchpad_create(struct evdev_device *device);
static int
path_get_udev_properties(const char *path,
char **sysname,
+ char **syspath,
char **seat_name,
char **seat_logical_name)
{
goto out;
*sysname = strdup(udev_device_get_sysname(device));
+ *syspath = strdup(udev_device_get_syspath(device));
seat = udev_device_get_property_value(device, "ID_SEAT");
*seat_name = strdup(seat ? seat : default_seat);
{
struct path_seat *seat;
struct evdev_device *device = NULL;
- char *sysname = NULL;
+ char *sysname = NULL, *syspath = NULL;
char *seat_name = NULL, *seat_logical_name = NULL;
- if (path_get_udev_properties(devnode, &sysname,
+ if (path_get_udev_properties(devnode, &sysname, &syspath,
&seat_name, &seat_logical_name) == -1) {
log_info(&input->base,
"failed to obtain sysname for device '%s'.\n",
}
}
- device = evdev_device_create(&seat->base, devnode, sysname);
+ device = evdev_device_create(&seat->base, devnode, sysname, syspath);
libinput_seat_unref(&seat->base);
if (device == EVDEV_UNHANDLED_DEVICE) {
out:
free(sysname);
+ free(syspath);
free(seat_name);
free(seat_logical_name);
struct evdev_device *device;
const char *devnode;
const char *sysname;
+ const char *syspath;
const char *device_seat, *seat_name, *output_name;
const char *calibration_values;
float calibration[6];
devnode = udev_device_get_devnode(udev_device);
sysname = udev_device_get_sysname(udev_device);
+ syspath = udev_device_get_syspath(udev_device);
/* Search for matching logical seat */
seat_name = udev_device_get_property_value(udev_device, "WL_SEAT");
return -1;
}
- device = evdev_device_create(&seat->base, devnode, sysname);
+ device = evdev_device_create(&seat->base, devnode, sysname, syspath);
libinput_seat_unref(&seat->base);
if (device == EVDEV_UNHANDLED_DEVICE) {