summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2014-11-20 13:36:32 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2014-11-25 16:32:37 +1000
commit8d24cd530425f3860c4a55a987b9d74f029c8d91 (patch)
treecb3b016eaf926fb5ebd4e3965eaced237c4e5140
parent92d178f167302665d51b3dba79d18de4c1881bdb (diff)
downloadlibinput-8d24cd530425f3860c4a55a987b9d74f029c8d91.tar.gz
path: keep the udev context around
We need it for each device anyway, keep the ref around. Makes error handling a bit easier, we don't need to handle failing udev_new() and reduce the danger of mis-refcounting it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--src/path.c31
-rw-r--r--src/path.h1
2 files changed, 19 insertions, 13 deletions
diff --git a/src/path.c b/src/path.c
index 37527512..f986afda 100644
--- a/src/path.c
+++ b/src/path.c
@@ -110,22 +110,18 @@ path_seat_get_named(struct path_input *input,
}
static int
-path_get_udev_properties(const char *path,
+path_get_udev_properties(struct udev *udev,
+ const char *path,
char **sysname,
char **syspath,
char **seat_name,
char **seat_logical_name)
{
- struct udev *udev = NULL;
struct udev_device *device = NULL;
struct stat st;
const char *seat;
int rc = -1;
- udev = udev_new();
- if (!udev)
- goto out;
-
if (stat(path, &st) < 0)
goto out;
@@ -147,8 +143,6 @@ path_get_udev_properties(const char *path,
out:
if (device)
udev_device_unref(device);
- if (udev)
- udev_unref(udev);
return rc;
}
@@ -160,8 +154,12 @@ path_device_enable(struct path_input *input, const char *devnode)
char *sysname = NULL, *syspath = NULL;
char *seat_name = NULL, *seat_logical_name = NULL;
- if (path_get_udev_properties(devnode, &sysname, &syspath,
- &seat_name, &seat_logical_name) == -1) {
+ if (path_get_udev_properties(input->udev,
+ devnode,
+ &sysname,
+ &syspath,
+ &seat_name,
+ &seat_logical_name) == -1) {
log_info(&input->base,
"failed to obtain sysname for device '%s'.\n",
devnode);
@@ -229,6 +227,8 @@ path_input_destroy(struct libinput *input)
struct path_input *path_input = (struct path_input*)input;
struct path_device *dev, *tmp;
+ udev_unref(path_input->udev);
+
list_for_each_safe(dev, tmp, &path_input->path_list, link) {
free(dev->path);
free(dev);
@@ -247,20 +247,25 @@ libinput_path_create_context(const struct libinput_interface *interface,
void *user_data)
{
struct path_input *input;
+ struct udev *udev;
if (!interface)
return NULL;
- input = zalloc(sizeof *input);
- if (!input)
+ udev = udev_new();
+ if (!udev)
return NULL;
- if (libinput_init(&input->base, interface,
+ input = zalloc(sizeof *input);
+ if (!input ||
+ libinput_init(&input->base, interface,
&interface_backend, user_data) != 0) {
+ udev_unref(udev);
free(input);
return NULL;
}
+ input->udev = udev;
list_init(&input->path_list);
return &input->base;
diff --git a/src/path.h b/src/path.h
index 779d8232..999601b4 100644
--- a/src/path.h
+++ b/src/path.h
@@ -28,6 +28,7 @@
struct path_input {
struct libinput base;
+ struct udev *udev;
struct list path_list;
};