summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2018-06-13 13:38:09 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2018-06-15 12:37:31 +1000
commit68f124b9791191f26fa3ac95cc8307e9a23b04db (patch)
treee9b57ec9129a87e6cb5ba6237109d7e2a4002548
parente1fe0cd5c5c046a740e14f76563a6952fdd3396e (diff)
tools: fix grab argument passing for libinput debug-events
The &grab pointer we used to pass as userdata was the address of the function argument which goes out of scope at the end of the function. This works fine for devices immediately opened but when a device connects later, the address may have been re-used since and it's content is undefined. If not NULL, we end up grabbing the device. Instead pass the grab option in which is guaranteed to live until the end of main. https://gitlab.freedesktop.org/libinput/libinput/issues/26 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> (cherry picked from commit 0a13223c39fdf0f079715bf83d498c0dcd9cf4f8)
-rw-r--r--tools/libinput-debug-events.c2
-rw-r--r--tools/libinput-debug-gui.c2
-rw-r--r--tools/shared.c10
-rw-r--r--tools/shared.h2
4 files changed, 8 insertions, 8 deletions
diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c
index 9bf9d52f..962ab09b 100644
--- a/tools/libinput-debug-events.c
+++ b/tools/libinput-debug-events.c
@@ -991,7 +991,7 @@ main(int argc, char **argv)
return 1;
}
- li = tools_open_backend(backend, seat_or_device, verbose, grab);
+ li = tools_open_backend(backend, seat_or_device, verbose, &grab);
if (!li)
return 1;
diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c
index f838b08b..6ed6c4a7 100644
--- a/tools/libinput-debug-gui.c
+++ b/tools/libinput-debug-gui.c
@@ -958,7 +958,7 @@ main(int argc, char **argv)
return 1;
}
- li = tools_open_backend(backend, seat_or_device, verbose, grab);
+ li = tools_open_backend(backend, seat_or_device, verbose, &grab);
if (!li)
return 1;
diff --git a/tools/shared.c b/tools/shared.c
index c1ce6473..d1f02702 100644
--- a/tools/shared.c
+++ b/tools/shared.c
@@ -251,7 +251,7 @@ static const struct libinput_interface interface = {
};
static struct libinput *
-tools_open_udev(const char *seat, bool verbose, bool grab)
+tools_open_udev(const char *seat, bool verbose, bool *grab)
{
struct libinput *li;
struct udev *udev = udev_new();
@@ -261,7 +261,7 @@ tools_open_udev(const char *seat, bool verbose, bool grab)
return NULL;
}
- li = libinput_udev_create_context(&interface, &grab, udev);
+ li = libinput_udev_create_context(&interface, grab, udev);
if (!li) {
fprintf(stderr, "Failed to initialize context from udev\n");
goto out;
@@ -285,12 +285,12 @@ out:
}
static struct libinput *
-tools_open_device(const char *path, bool verbose, bool grab)
+tools_open_device(const char *path, bool verbose, bool *grab)
{
struct libinput_device *device;
struct libinput *li;
- li = libinput_path_create_context(&interface, &grab);
+ li = libinput_path_create_context(&interface, grab);
if (!li) {
fprintf(stderr, "Failed to initialize context from %s\n", path);
return NULL;
@@ -315,7 +315,7 @@ struct libinput *
tools_open_backend(enum tools_backend which,
const char *seat_or_device,
bool verbose,
- bool grab)
+ bool *grab)
{
struct libinput *li;
diff --git a/tools/shared.h b/tools/shared.h
index 55e15409..0a9c1e64 100644
--- a/tools/shared.h
+++ b/tools/shared.h
@@ -104,7 +104,7 @@ int tools_parse_option(int option,
struct libinput* tools_open_backend(enum tools_backend which,
const char *seat_or_device,
bool verbose,
- bool grab);
+ bool *grab);
void tools_device_apply_config(struct libinput_device *device,
struct tools_options *options);
int tools_exec_command(const char *prefix, int argc, char **argv);