Commit graph

615 commits

Author SHA1 Message Date
Peter Hutterer
ab2ab19ca3 tools: make to function calls static
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-17 20:11:38 +10:00
Peter Hutterer
64efc0b5bf Fix a typo in the uinput documentation
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-17 20:11:38 +10:00
Peter Hutterer
001d194c19 Move libevdev_led_value documentation to the kernel group
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-17 20:11:38 +10:00
Colin Walters
34fc7ee425 tools: Honor GCC_CFLAGS
So we get compiler warnings from tools/ too.

Signed-off-by: Colin Walters <walters@verbum.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-17 20:11:32 +10:00
Peter Hutterer
e156f9a11c Drop duplicate compiler flag
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-16 16:00:06 +10:00
Peter Hutterer
3dc41b29b7 Revert "Reintroduce -fstack-protector"
http://lists.freedesktop.org/archives/input-tools/2013-September/000332.html
See above a detailed reasoning, but Colin Walters put it this way:

"At a high level, I think components (git repositories) should feel free
to set up default warning flags and possibly use a targeted subset of
-Werror=foo.  But please don't inject non-warning flags like this unless
there is a very good reason.

The right way to do -fstack-protector is to have something like
redhat-rpm-config or other global CFLAGS system controlling *all*
components."

Thus, reverting the -fstack-protector flag. This doesn't completely address
Colin's comments, we still use a few other flags. But this one is the one
that causes real headaches, so drop it.

This reverts commit f5e65ea3ce.
2013-09-16 15:55:10 +10:00
David Herrmann
f5e65ea3ce Reintroduce -fstack-protector
We removed this previously due to build failures in:

  commit 14ac764ec8
  Author: David Herrmann <dh.herrmann@gmail.com>
  Date:   Mon Sep 9 16:03:41 2013 +0200

      build: remove -fstack-protector

Reintroduce it but this time disable it if it's not supported. We use the
CC-flags testing to prevent build-failures on gcc without libssp support.

Cc: Giovanni Campagna <gcampagn@redhat.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-13 15:51:23 +10:00
David Herrmann
92b2b1ccd5 Test for CFLAGS/LFLAGS availability
Use the CC_CHECK_FLAGS_APPEND() m4 macro to test for availability of
CFLAGS and LFLAGS. It automatically drops the unavailable flags.

This is also used by systemd, so it ought to work with ostree and other
non-standard build-environments.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-13 15:49:50 +10:00
Peter Hutterer
1e81ac1e28 wrap EVIOCSCLOCKID into an API call
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-13 09:28:00 +10:00
Peter Hutterer
c299ab3c5e test: provide wrapper for fetching the devnode from a uinput test device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-13 08:59:06 +10:00
Peter Hutterer
b539cfd808 test: add a test for checking log data being passed around correctly
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-12 14:28:05 +10:00
Peter Hutterer
a263d7f71b Fix a comment to reflect the new API
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-12 14:15:56 +10:00
Peter Hutterer
64e1ed2cef Remove warning comment from FORCE_SYNC
There is a legitimate reason for clients to force a sync on the device.
X.Org drivers lose the fd when the device is disabled and re-enabled. When
the device comes back, a simple libevdev_change_fd() doesn't update the status
on the device.

Button states, etc. may have changed, etc. So a driver may call FORCE_SYNC after
re-connecting to the fd to make sure the library and the driver get the current
state of the device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-11 12:10:15 +10:00
Peter Hutterer
661602fe3b Name-space the read flags better
Rename from LIBEVDEV_READ_foo to LIBEVDEV_READ_FLAG_foo to differentiate
better from LIBEVDEV_READ_STATUS_foo.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-11 12:10:15 +10:00
Peter Hutterer
5d2fc78138 Enumerate libevdev_next_event() return codes
Improved readability in callers, changing magic numbers 0 and 1 to

rc = libevdev_next_event();
if (rc == LIBEVDEV_READ_STATUS_SUCCESS)
    do_something();
else if (rc == LIBEVDEV_READ_STATUS_SYNC)
    do_something_else()

No ABI changes, the enum values are the previously documented values,
this is just a readability improvement.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-11 12:10:12 +10:00
Peter Hutterer
7421760eae Require check 0.9.9
0.9.9 is the first released version with fixed ck_assert_* macros that don't do
multiple expansion.

http://sourceforge.net/p/check/code/596/

Reported-by: Martin Minarik <minarik11@student.fiit.stuba.sk>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-11 12:07:51 +10:00
Peter Hutterer
37a69d5675 Fix comment typo
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-11 12:06:08 +10:00
Peter Hutterer
dab889781b doc: don't show enum values in doxygen
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-11 12:06:08 +10:00
Peter Hutterer
4eb87a113a Add missing group assignment to a bunch of functions and enumerations
Without these, they won't show up in the documentation.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-11 12:05:54 +10:00
Peter Hutterer
ab2f20bfd6 Revamp the API once again
Another look at the current API showed some inconsistencies, rectified
in this commit:

libevdev_kernel_*: modify the underlying kernel device
libevdev_event_type_*: something with an event type
libevdev_event_code_*: something with an event code
libevdev_event_*: struct input_event-related functions (i.e. not device-related)
libevdev_property_*: something with a property
libevdev_*: anything applying to a device

Hopefully that's the last API change. Current symbols deprecated and aliased.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-10 11:25:09 +10:00
David Herrmann
14ac764ec8 build: remove -fstack-protector
If gcc is built without libssp support, it loudly fails linking due to
missing __stack_chk_*() helpers. Unfortunately, gcc isn't smart enough to
disable it automatically.

systemd recently got a CC_CHECK_FLAG_APPEND helper to work around such
issues:
  http://cgit.freedesktop.org/systemd/systemd/tree/m4/attributes.m4

I didn't want to add it now, so let's just drop -fstack-protector. If we
want it, we can try adding it later again.

This partially reverts:
  commit 43752ec17d
  Author: David Herrmann <dh.herrmann@gmail.com>
  Date:   Sun Sep 1 17:45:04 2013 +0200

      Add some gcc/ld optimizations and magic

All other gcc/ld options are kept.

Reported-by: Giovanni Campagna <gcampagn@redhat.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-10 10:18:06 +10:00
Giovanni Campagna
5b28e0292d configure: add missing comma
Without that, it becomes impossible to build without gcov.

Signed-off-by: Giovanni Campagna <scampa.giovanni@gmail.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-10 10:01:19 +10:00
Giovanni Campagna
929705cb7b Support GNOME Build API
By adding an autogen.sh file with NOCONFIGURE support.

Signed-off-by: Giovanni Campagna <scampa.giovanni@gmail.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-10 10:01:14 +10:00
Peter Hutterer
0adb75e2eb Merge branch 'logging-fix' 2013-09-10 09:59:11 +10:00
Peter Hutterer
112ac0351f test: test for logging function
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-10 09:54:29 +10:00
Peter Hutterer
ad709cf953 Log to stderr by default
The logging we do use atm inside the library is largely
to spot application errors. Log that to stderr by default so
it doesn't get lost.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-10 09:37:59 +10:00
Peter Hutterer
32a9ee109e Fix comment typo
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-04 07:54:23 +10:00
Peter Hutterer
75b66c1fb5 Match the kernel define for SYN_MAX
Will be defined as 0xf in 3.12, see
http://git.kernel.org/cgit/linux/kernel/git/dtor/input.git/commit/?h=next&id=52764fed5049655926bcecaefd52f0a415ceb105

And add the required ifdef guards for kernels before that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-04 07:54:22 +10:00
Peter Hutterer
0b712e6f86 Check for GNU ld and use the flags depending on the outcome
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2013-09-04 07:54:09 +10:00
Peter Hutterer
4b5ffa6bea Warn if there are multiple devices with the same syspath
Change to the previous code in that we continue looking at devices
even after we've found one. However, this way we can warn
the user when we can't guarantee syspath correctness.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-03 17:01:42 +10:00
Peter Hutterer
a6e25fab76 Log a few errors, specifically application bugs
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-03 17:01:40 +10:00
Peter Hutterer
55d67a340b Drop per-device logging function, use per-library one instead
There's no need to have separate logging function for each device created.
More likely, libevdev will be hooked up once into the logging system and
expected to deal with it.

Plus, this allows us to log from the uinput code where we don't
have the context anyway.

Requires a rename to libevdev_set_log_function to avoid ABI breaks, and
while we're breaking the ABI make the logging function more sophisticated
to log line, number, etc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-03 16:58:54 +10:00
David Herrmann
95df174f06 Remove -g from default GCC_CFLAGS
-g should be set by debugging-options or in the default CFLAGS="", we
shouldn't force it in GCC_CFLAGS.

Reported-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-03 07:31:40 +10:00
David Herrmann
43752ec17d Add some gcc/ld optimizations and magic
There are several gcc/ld flags that optimize size and performance without
requiring explicit code changes. In no particular order, this adds:
 - gcc -pipe to avoid temporary files and use pipes during compilation
 - gcc -fno-common avoids putting uninitialized global variables not
   marked as "extern" into a common section. This catches compilation
   errors if we didn't mark global variables explicitly as "extern".
 - gcc -fno-strict-aliasing allows us to use unions for some binary magic.
   Otherwise, -O2 might assume that two different types never point at the
   same memory. We currently don't rely on this but it's common practice
   so avoid any non-obvious runtime errors later.
 - gcc -ffunction-sections and -fdata-sections put each function and
   variable into a separate section. This enables ld's --gc-sections to
   drop any unused sections (sections which aren't referenced from an
   exported section). This is very useful to avoid putting dead code into
   DSOs. We can now link any helper function into libevdev and the linker
   removes all of them if they're unused.
 - gcc -fstack-protector adds small stack-corruption protectors in
   functions which have big buffers on the stack (>8bytes). If the
   stack-protectors are corrupted, the process is aborted. This is highly
   useful to debug stack-corruption issues which often are nearly
   impossible to catch without this.
 - ld --as-needed drops all linked libraries that are not actually
   required by libevdev. So we can link to whatever we want and the linker
   will drop everything which is not actually used.
 - ld -z now, resolve symbols during linking, not during runtime.
 - ld -z relro, add relocation-read-only section. This allows to put
   read-only global variables and alike into a read-only section. This is
   useful for variables that need a relocation and thus cannot be
   explicitly put into a read-only section. This option tells the linker
   to mark them read-only after relocations are done. (that's why -z now
   makes sense in combination with this)

All of these options are common in other open-source projects, including
systemd and weston. Don't ask me why they are not marked as default..

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-09-03 07:31:33 +10:00
Peter Hutterer
37d37cdaea uinput: don't try to set the syspath twice
If we have it, stop searching for it. Otherwise a second device with the
same name would overwrite the first, causing a leak.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 13:17:58 +10:00
Peter Hutterer
22d2a735c4 Return -EBADF for functions that need the fd initialized
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 13:17:56 +10:00
Peter Hutterer
2c101977b7 Return EBADF when trying to read from an uninitalized device
All other functions that check the fd for validity return EBADF, which also makes it
easier to debug if the actual device goes away.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 13:17:26 +10:00
Peter Hutterer
9675287062 Use ENOMEM instead of ENOSPC
From errno(3):
   ENOMEM          Not enough space (POSIX.1)
   ENOSPC          No space left on device (POSIX.1)

when we run out memory the reason is a failed malloc, for which ENOMEM
seems more appropriate.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 12:27:23 +10:00
Peter Hutterer
69f89c8877 test: update to test for the various _MAX values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 09:40:41 +10:00
Peter Hutterer
4417a6a1c1 memcpy instead of invidual bittoggle
The ioctls return the number of bytes copied into the destination, so just
copy them into the device state instead of individually flipping bits.

For easier review: rc is the return value of the EVIOCG* ioctl, which is
the number of bytes copied.

state variables must be initialized to 0 now, in case the kernel's FOO_MAX
is smaller than libevdev's FOO_MAX. If not initialized to 0, the bytes
between the two max values is undefined and we may end up generating bogus
events.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 09:40:17 +10:00
Peter Hutterer
e372c4a6bd test: add a test for uinput device properties
Specifically, test for INPUT_PROP_MAX, which is a valid property value

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-30 17:41:02 +10:00
Peter Hutterer
b77fea9c89 Fix off-by-one errors when dealing with *_MAX values.
LED_MAX, KEY_MAX, ABS_MT_MAX, etc. are all valid event codes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-30 17:40:54 +10:00
Peter Hutterer
a8871e7aea Use AC_USE_SYSTEM_EXTENSIONS
Defines _GNU_SOURCE for us.
http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Posix-Variants.html

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:54:50 +10:00
Peter Hutterer
da425202c1 test: fix ev_rep test for new uinput implementation
We can actually set EV_REP values now, though with limitations

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 13:54:49 +10:00
Peter Hutterer
cc2eaec4ed test: switch udev backend over to new libevdev-uinput bits
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:54:49 +10:00
Peter Hutterer
21356cca57 test: add uinput creation tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 13:54:49 +10:00
Peter Hutterer
1acbfb3579 Add support for uinput device creation
This lets libevdev provide a relatively generic interface for the
creation of uinput devices so we don't need to duplicate this across
multiple projects.

Most of this is lifted from the current test implementation, with a
couple of minor changes.

EV_REP needs special handling:
   Kernel allows to set the EV_REP bit, it doesn't set REP_* bits (which we
   wrap anyway) but it will also set the default values (500, 33).

Device node is guessed based on the sysfs path:
   The sysfs path contains a eventN file, that corresponds to our
   /dev/input/eventN number. Use it so clients can quickly get the device
   node, without a libudev dependency.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:54:46 +10:00
Peter Hutterer
1b7c46b2f1 Fix two signed vs unsigned int warnings
dev->num_slots is -1 if we don't have ABS_MT_SLOT.

Set dev->grabbed to the right field type.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:20:07 +10:00
Peter Hutterer
30a65d20e9 Actually use the gcc CFLAGS set in configure
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:02:53 +10:00
Peter Hutterer
7060206aca Mark all external symbols with LIBEVDEV_EXPORT
GCC_CFLAGS was set by configure, but never actually used. So we didn't build with hidden symbols,
rather just weeded them out later through libtool.

Do this properly now, mark the symbols as visibility default.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:02:53 +10:00