struct evdev_device *
evdev_device_create(struct libinput_seat *seat,
const char *devnode,
- const char *sysname,
- int fd)
+ const char *sysname)
{
struct libinput *libinput = seat->libinput;
struct evdev_device *device;
char devname[256] = "unknown";
+ int fd;
+
+ /* Use non-blocking mode so that we can loop on read on
+ * evdev_device_data() until all events on the fd are
+ * read. mtdev_get() also expects this. */
+ fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
+ if (fd < 0) {
+ log_info("opening input device '%s' failed (%s).\n",
+ devnode, strerror(-fd));
+ return NULL;
+ }
device = zalloc(sizeof *device);
if (device == NULL)
return device;
err:
+ if (fd >= 0)
+ close_restricted(libinput, fd);
evdev_device_destroy(device);
return NULL;
}
if (device->mtdev)
mtdev_close_delete(device->mtdev);
- close(device->fd);
+ close_restricted(device->base.seat->libinput, device->fd);
list_remove(&device->base.link);
notify_removed_device(&device->base);
struct evdev_device *
evdev_device_create(struct libinput_seat *seat,
const char *devnode,
- const char *sysname,
- int fd);
+ const char *sysname);
struct evdev_dispatch *
evdev_touchpad_create(struct evdev_device *device);
struct evdev_device *device = input->device;
if (device) {
- close_restricted(libinput, device->fd);
evdev_device_remove(device);
input->device = NULL;
}
struct evdev_device *device;
const char *devnode = input->path;
char *sysname;
- int fd;
char *seat_name, *seat_logical_name;
if (input->device)
return 0;
- fd = open_restricted(libinput, devnode, O_RDWR|O_NONBLOCK);
- if (fd < 0) {
- log_info("opening input device '%s' failed (%s).\n",
- devnode, strerror(-fd));
- return -1;
- }
-
if (path_get_udev_properties(devnode, &sysname,
&seat_name, &seat_logical_name) == -1) {
- close_restricted(libinput, fd);
log_info("failed to obtain sysname for device '%s'.\n", devnode);
return -1;
}
free(seat_name);
free(seat_logical_name);
- device = evdev_device_create(&seat->base, devnode, sysname, fd);
+ device = evdev_device_create(&seat->base, devnode, sysname);
free(sysname);
libinput_seat_unref(&seat->base);
if (device == EVDEV_UNHANDLED_DEVICE) {
- close_restricted(libinput, fd);
log_info("not using input device '%s'.\n", devnode);
return -1;
} else if (device == NULL) {
- close_restricted(libinput, fd);
log_info("failed to create input device '%s'.\n", devnode);
return -1;
}
static int
device_added(struct udev_device *udev_device, struct udev_input *input)
{
- struct libinput *libinput = &input->base;
struct evdev_device *device;
const char *devnode;
const char *sysname;
const char *device_seat, *seat_name, *output_name;
const char *calibration_values;
- int fd;
struct udev_seat *seat;
device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
return -1;
}
- /* Use non-blocking mode so that we can loop on read on
- * evdev_device_data() until all events on the fd are
- * read. mtdev_get() also expects this. */
- fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
- if (fd < 0) {
- log_info("opening input device '%s' failed (%s).\n",
- devnode, strerror(-fd));
- libinput_seat_unref(&seat->base);
- return 0;
- }
-
- device = evdev_device_create(&seat->base, devnode, sysname, fd);
+ device = evdev_device_create(&seat->base, devnode, sysname);
libinput_seat_unref(&seat->base);
if (device == EVDEV_UNHANDLED_DEVICE) {
- close_restricted(libinput, fd);
log_info("not using input device '%s'.\n", devnode);
return 0;
} else if (device == NULL) {
- close_restricted(libinput, fd);
log_info("failed to create input device '%s'.\n", devnode);
return 0;
}
evdev_udev_handler(void *data)
{
struct udev_input *input = data;
- struct libinput *libinput = &input->base;
struct udev_device *udev_device;
struct evdev_device *device, *next;
const char *action;
if (!strcmp(device->devnode, devnode)) {
log_info("input device %s, %s removed\n",
device->devname, device->devnode);
- close_restricted(libinput, device->fd);
evdev_device_remove(device);
break;
}
libinput_seat_ref(&seat->base);
list_for_each_safe(device, next,
&seat->base.devices_list, base.link) {
- close_restricted(&input->base, device->fd);
evdev_device_remove(device);
if (list_empty(&seat->base.devices_list)) {
/* if the seat may be referenced by the
li = libinput_create_from_path(&simple_interface, NULL, path);
ck_assert(li == NULL);
- ck_assert_int_eq(open_func_count, 1);
+ ck_assert_int_eq(open_func_count, 0);
ck_assert_int_eq(close_func_count, 0);
libinput_destroy(li);