Commit graph

390 commits

Author SHA1 Message Date
Benjamin Tissoires
d3ae3da90f Send an extra ABS_MT_SLOT event to sync the client up with the current slot
If multiple slots have changed during the sync handling, the client must be
re-set to the current slot before continuing with normal events.

Signed-off-by: Benjamin Tissoires <btissoir@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-07 10:16:11 +10:00
Peter Hutterer
12ff51b871 Don't sync the MT state for fake MT devices
Devices with ABS_MT_SLOT-1 are fake MT devices, they merely overlap the
axis range but don't actually provide slots. The EVIOCGABS ioctl won't work to
retrieve the current value - the kernel does not store values for those axes
and the return value is always 0.

Thus, simply ignore those axes for fake MT devices and instead rely on the
next event to update the caller with the correct state for each axis.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 14:30:03 +10:00
Peter Hutterer
68a297577a Move some functions/macros between libevdev-int.h and libevdev-util.h
This allows libevdev-util.h to be used by tests, it no longer relies on
libevdev internal structs.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 14:30:03 +10:00
Peter Hutterer
66fee1bec4 Cap slot values to the announced maximum
A malicious device may announce N slots but then send a slot index >= N. The
slot state is almost always allocated (definitely the case in libevdev and
true for most callers), so providing a slot number higher than the announced
maximum is likely to lead to invalid dereferences. Don't allow that.
Likewise, don't allow negative slot numbers.

Note that the kernel filters these events anyway, the only way to trigger this
is to change the device fd to something outside the kernel's control.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 14:30:03 +10:00
Peter Hutterer
4ba56ac309 test: add two more checks for the current slot
When syncing, we expect the slot to stay the same until the client has
processed the events. This already worked, just add a check to make sure.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-06 09:21:02 +10:00
Peter Hutterer
f3f31b47fc Increase MAX_SLOTS to 60
As seen on 3M devices, which seems to be the maximum seen so far. Some Stantum
devices report 255 touches but are only capable of 10, so the are not affected
by our limits.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 09:21:02 +10:00
Peter Hutterer
d596bd7a32 test: add a test for > MAX_SLOTS mt values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 09:21:02 +10:00
Peter Hutterer
24c9ca81f0 Reduce memory requirement for MT syncing
Changes the algorithm: before we'd ioctl all axes for all slots, then generate
events for all slots one-by-one.

Now we ioctl the slot state for each axis, copy the new event value into
the device and mark a bitfield that we've updated the value. Then loop through
the slots and generate events where changed.

Side-effect: this makes it easy to check if anything in the slot has updated,
so we can skip empty slot events during sync.

Min memory requirement for the state storage was:
  MAX_SLOTS  * (ABS_MT_CNT + 1) * sizeof(int) = 1980
Min memory requirement now:
  (ABS_MT_CNT + 1) * sizeof(int) + NLONGS((MAX_SLOTS * ABS_MT_CNT) bits) = 544

This is sigsafe code, so this was stack memory. Reducing the requirement
allows us to up MAX_SLOTS in the future if we need to.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 09:21:02 +10:00
Peter Hutterer
89e7998fee Dynamically allocate the slot values
Instead of relying on a static MAX_SLOTS array, allocated it based on the
number of slots we have on the device. The previous checks for MAX_SLOTS were
incomplete, causing out-of-bound reads.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-06 09:21:02 +10:00
Peter Hutterer
2e06aed955 Don't sync past MAX_SLOTS slots
If a device has more than MAX_SLOTS slots, we'd run out-of-bounds on the sync
array. This function is sig-safe, so we can't alloc here, merely limit the
access.

Reported-by: Jonas Ådahl <jadahl@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 09:21:02 +10:00
Peter Hutterer
5b0b2ae114 Add unlikely() macro
Taken from systemd.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-06 09:21:02 +10:00
Peter Hutterer
4390845fd2 Fix a wrong reference in the libevdev_next_event documentation
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-06 09:12:24 +10:00
Peter Hutterer
0deacd5c1e Document the FORCE_SYNC behavior a bit better
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-05 19:16:14 +10:00
Peter Hutterer
b08ed615d3 test: whitespace fixes (newlines)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-05 19:16:08 +10:00
Peter Hutterer
fdf737494e Fix memory leaks when failing to create a uinput device
For an invalid fd, or a failure to open the device, the pre-allocated uinput
device struct would leak.

We can drop the open_uinput() function now, since skipping to the error
handling means we'll return -errno anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-27 13:22:50 +10:00
Peter Hutterer
f162f00f1d Plug a memory leak for name, uniq, phys
If a device is assigned a name, uniq and/or phys before calling
libevdev_set_fd(), those values would leak.

Change the default alloc to calloc, so name, uniq, and phys are initialized to
zero before we call libevdev_reset

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-27 13:19:36 +10:00
Peter Hutterer
05c061c2bc test: plug more memory leaks
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-27 13:19:12 +10:00
Peter Hutterer
128cdcf105 test: fix memleak when using the test-uinput device
The libevdev-created uinput device was never freed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-27 11:08:51 +10:00
Emmanuele Bassi
84d2d5034c tools: Fix compiler warning
Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-26 07:24:46 +10:00
Emmanuele Bassi
b215120e39 Fix the include directives when building in tools/
We need to add top_srcdir to fix the build when srcdir != builddir.

Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-26 07:23:45 +10:00
Peter Hutterer
061927dd76 Add a test for EVIOCREVOKE
New in 3.12, EVIOCREVOKE revokes access to an evdev device. This is unlikely
to be used by a libevdev user, see.
http://lists.freedesktop.org/archives/input-tools/2014-January/000688.html

This patch adds a new test-kernel binary that tests the kernel API directly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-02-26 07:22:04 +10:00
Peter Hutterer
2c4daec150 Document that the return value of get_name|uniq|phys is not permanent
It's a pointer to the copy libevdev has, but that copy may be freed by the
caller if someone calls e.g. libevdev_set_name()

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-25 13:18:21 +10:00
Peter Hutterer
5250243b6f tools: add a tool to print the actual range provided by a touchpad
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-25 13:18:18 +10:00
Peter Hutterer
a5a06035f9 Replace hardcoded 0 with the enum for it
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-25 13:05:33 +10:00
Peter Hutterer
f01a887b30 test: remove a bunch of superfluous empty lines
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-25 13:05:30 +10:00
Peter Hutterer
cf70d0cd88 libevdev 1.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-18 14:51:23 +10:00
Peter Hutterer
50b82c19b5 Actually filter by log priority
If a message is higher than the current priority, filter it. And add a few
tests that the priority is handled the way it should.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-02-13 08:07:30 +10:00
Peter Hutterer
0d593bff71 Use 0 instead of "zero"
We're a bit inconsistent here anyway because of the ample use of "non-zero"
which can't really be converted to non-0. But let's at least be consistent
with the use of 0 instead of zero.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-12 16:01:10 +10:00
Peter Hutterer
069236334c More documentation fixes and improvements
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-12 16:01:10 +10:00
Peter Hutterer
fd01f895b6 Mark a few more functions as signal-safe
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-12 15:47:33 +10:00
Peter Hutterer
7e8ba41a40 Improve the documentation a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-11 16:46:49 +10:00
Peter Hutterer
4b3d2405e3 Document that we don't support EVIOCREVOKE
This is intentional, see
http://lists.freedesktop.org/archives/input-tools/2014-January/000688.html

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-11 16:46:49 +10:00
Peter Hutterer
2a06d3e182 README: remove the warning, it's stable now
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-11 16:27:50 +10:00
Peter Hutterer
da6de93985 libevdev 0.9.1
libevdev 1.0-rc1

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-29 15:09:05 +10:00
Peter Hutterer
6c2b01d67f test: remove NULL test for SW_MAX, 3.13 defines SW_MUTE_DEVICE
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-29 15:08:12 +10:00
Peter Hutterer
def04e91e7 Bump soname
Bump once to the stable interface we have now. This isn't really required as
we're compatible with everything but functions deprecated with 0.4 but we
might as well do it now to force a rebuild of everyone. Should've done that
for 0.6 when we actually dropped the function, but ...

Now that we have proper library versioning we shouldn't need any
backwards-incompatible soname bumps for a while.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-01-29 15:02:45 +10:00
David Herrmann
5f40be0b43 Add ld version-script
Explicit symbol versioning allows us to provide multiple versions of
incompatible API changes. It is a very common practice in GNU world and
avoids the problems occuring if distributions try to ship multiple version
of a single DSO.

Background information available at:
  http://people.redhat.com/drepper/dsohowto.pdf

To see the symbol-versions, use objdump:
  objdump -T libevdev/.libs/libevdev.so.1.0.0
This can also be used to verify that all symbols are correctly
exported (typos in linker-scripts are silently ignored by ld).

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

Updated for evdev 0.6's API.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-29 15:02:40 +10:00
Peter Hutterer
8356f417df include: update linux/input.h for kernel 3.13
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 09:15:14 +10:00
Peter Hutterer
642c91fc6a Warn about a SYN_DROPPED right after finishing a sync
If the first event after a completed device sync is a SYN_DROPPED, warn the
user that they're not fast enough handling this device.

The test for this is rather complicated since we can't write SYN_DROPPED
through uinput so we have to juggle the device fd and a pipe and switch
between the two at the right time (taking into account that libevdev will read
events from the fd whenever it can).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 09:15:14 +10:00
Peter Hutterer
0c01886985 test: abort on unexpected log messages
Add two log functions, one that aborts on a received message. We know when we
expect to receive an error, so anytime this happens unexpectedly should
terminate the test.

And for those tests do issue a log message, let them ignore it and don't
print anything.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 09:14:40 +10:00
Peter Hutterer
77bf0fe228 Count the number of events needed for a full sync
Make sure we have a queue that is at least large enough to do a full sync
after a SYN_DROPPED, plus store a few extra events in case some came in after
the sync.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-01-22 08:28:41 +10:00
Peter Hutterer
4eeda3bc47 test: fix typo
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-17 10:54:58 +10:00
Peter Hutterer
650f372c90 test: rename a test to match what it's testing better
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-17 10:54:58 +10:00
Peter Hutterer
cea8f0b8cc Drop the argparse requirement for make-event-names.py
We only take one option (path to linux/input.h) anyway so drop the argparse
requirement. This way libevdev builds on RHEL6 too which doesn't ship
argparse.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-01-15 08:01:31 +10:00
Peter Hutterer
8f2a808cfa Drop --output flag and python generation code from make-event-names.py
This is a leftover from when the file was in evemu and used to generate python
headers too.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-01-15 08:00:18 +10:00
Peter Hutterer
d3c3486560 include: update linux/input.h for kernel 3.12
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-01-09 09:05:05 +10:00
Peter Hutterer
fd3118ea1a test: detect if we're running inside gdb and disable forking
The Check test framework forks by default which is annoying when running gdb.
Try to detect whether we're inside gdb by ptracing ourselves. If that works,
we're not inside a debugger. If it doesn't, then assume we're inside a
debugger and set CK_FORK to "no".

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-24 09:14:12 +10:00
Peter Hutterer
49f0b9300e Documentation rewordings and additions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-24 09:14:12 +10:00
Peter Hutterer
f87647b509 Documentation typo fixes
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-24 09:13:23 +10:00
Peter Hutterer
590291513b Add more cross-references
doxygen doesn't detect enum cross-references automatically, prefix them with
@ref

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-24 09:13:23 +10:00