Commit graph

621 commits

Author SHA1 Message Date
Peter Hutterer
005c4ac493 util: use xalloc instead of calloc to avoid NULL checks 2024-09-11 12:27:38 +10:00
Peter Hutterer
bbc1f8de1c util: fix a leaking fd in a test 2024-09-11 12:27:38 +10:00
Peter Hutterer
e3091a1802 util: fix a comment to use the right decimal marker for english 2024-09-11 12:27:38 +10:00
Peter Hutterer
22c94fd916 util: silence out-of-bounds read warning
gcc -fanalyze complains because it doesn't know the __stop section is
always greater than the __start section so it complains that we're
eventually reading past our __start section. Let's silence that with a
simple check.
2024-09-11 12:26:59 +10:00
Peter Hutterer
ec031bc4bf test: add a few non-null checks to make the static analyzer happy 2024-09-11 12:26:40 +10:00
Peter Hutterer
bf03c56300 Add a few missing va_end
Found by gcc -fanalyze
2024-09-11 12:25:41 +10:00
Peter Hutterer
37cc857a52 doc: demote the socket backend in the documentation
The socket backend is useful for debugging and testing but not for real
user-cases where the fd negotiation should be handled by the caller
(e.g. passing it down through the portal). Let's demote the socket
backend in favour of the fd backend.

Related https://gitlab.freedesktop.org/libinput/libei/-/issues/63
2024-09-03 04:00:33 +00:00
Peter Hutterer
e411b85a33 Print the event type name for invalid events 2024-08-07 10:47:25 +10:00
David Redondo
e8a844355f oeffis: Make ConnectToEIS call async
A blocking call can be  problematic when done from inside Xwayland
to the compositor as the compositor could be doing a blocking X call
at the same time. In this instance we found it's likely to happen
because this call will happen shortly after the user accepted the
This is not a problem for the other calls because the portal API
is async for these via request response signalling.
2024-07-31 07:05:48 +00:00
Peter Hutterer
865d7152e0 util: replace a strncpy with a memcpy
We know exactly the lengths of everything involved here so let's use
memcpy. This way we don't need the stringop-truncation warning (a pragma
clang doesn't support anyway).
2024-07-29 05:15:53 +00:00
Peter Hutterer
6ea468c823 util/memfile: use MAP_SHARED to create the map
Using MAP_PRIVATE means copy-on-write so our data written into the map
immediately disappears again. This leads to a empty string when sending
a keymap to a client.
2024-07-29 14:48:34 +10:00
Peter Hutterer
dc153c50ed util/memfile: include stddef for size_t 2024-07-29 14:48:34 +10:00
Peter Hutterer
c4ac084159 util/memmap: add a helper wrapper around mmap
Makes this easier to use with our unref functions.
2024-07-29 14:48:34 +10:00
Peter Hutterer
a424458f03 Devices without regions pass coordinates as-is
If a device doesn't have a region (e.g. physical device) the answer to
"is this in the region" is always yes.

Closes #56
2024-07-25 01:17:39 +00:00
Peter Hutterer
0f81114544 Fix region check for devices with multiple regions
Use the ei(s)_device_in_region() to check for any region.

Closes #56
2024-07-25 01:17:39 +00:00
David Redondo
23f056433d Fix API docs for EIS_EVENT_CLIENT_CONNECT
The functions with event in their name don't exist.
2024-04-09 06:39:13 +00:00
Peter Hutterer
d29778658a oeffis: OEFFIS_DEVICE_ALL_DEVICES should translate to "all"
As the portal documentation [1] says:
  Bitmask of what device types to request remote controlling of. Default is all.

The default is only triggered if we do not submit the types at all, the
current behavior of sending a value of 0 means "none". Fix this by
skipping the "types" key if we try to select for all devices.

[1] https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.impl.portal.RemoteDesktop.html
2023-12-14 00:58:18 +00:00
Peter Hutterer
38132d6fc5 ei: improve debug messages for keymap failures
Let's be more informative about what failed.

Fixes #48
2023-11-09 12:55:56 +10:00
Peter Hutterer
924341e174 ei: keep a cache of defunct objects to avoid spamming the log
Because of the asynchronous protocol, we may get this interaction

   server sends A->destroyed()
       client sends A->foo()
       client receives A->destroyed()
   server receives A->foo()
   server sends invalid_object_id(A)
       client receives invalid_object_id(A)

Previously we dropped the object after destroyed() and were thus
guaranteed to warn about the invalid object id for that same object
later.

Fix this by keeping a cache of defunct object IDs that we know about and
ignoring errors for recently dropped objects.

Every 20 ei_dispatch() calls we drop any defunct objects that were
unregistered more than 5 seconds ago.

Fixes #49
2023-11-09 12:47:06 +10:00
Peter Hutterer
4e634aa76c test: add the ability to add offsets to ei_now()
Build a separate libei-eierpecken.so that is identical to libei.so but
allows adding an offset to ei_now() for the eierpecken tests. That
offset is added to the return value of ei_now(), removing the real-time
dependency of the tests.

In other words, we can call peck_ei_add_time_offset(peck, s2us(5)) to
add 5 seconds to the time and continue the test as if that time has
elapsed.
2023-11-09 12:47:06 +10:00
Peter Hutterer
34c83370be eis: fix a typo 2023-11-08 23:24:45 +00:00
Peter Hutterer
d31b5a1ccf eis: only queue a seat bind event if the caps change
This triggered an internal bug message in test_ei_seat_bind_unbind_immediately.

If a client unbinds all capabilities this triggers an EIS_SEAT_BIND with
zero caps. peck would call eis_seat_remove() which calls eis_seat_drop().
That queued another EIS_EVENT_SEAT_BIND with zero capabilities, leading
peck to call eis_seat_remove() again on an already removed seat.
2023-11-08 23:24:45 +00:00
Peter Hutterer
f558eedae2 util: add a global setup option to our munit wrapper
This allows us to handle/manipulate argv and/or pass a userdata to the
tests. Same ELF section approach as we already have with the MUNIT_TEST
macro but this time it's for a global setup.

Note that for the generated __start and __stop section variables we have
to have at least one entry in that section which we do with one
hardcoded (and ignored) one.
2023-10-24 18:25:25 +10:00
Peter Hutterer
6758b9970d util: add helper macros for the ELF section handling 2023-10-24 18:25:25 +10:00
Peter Hutterer
19c949a46b util: retry posix_fallocate() if it fails
We block SIGALRM since d4bf8840a4 so any
remaining EINTR is something we should probably retry with.
2023-10-24 18:25:25 +10:00
Peter Hutterer
a3c801097d util: don't check for EINTR on close()
See https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/261#note_2131802
2023-10-24 18:25:25 +10:00
Peter Hutterer
cdbd1d9eaf util: replace most of SIGALRM blocks with EINTR checks
SIGALRM *should* not really be an issue for us, most of our IO shouldn't
take long (posix_fallocate is the exception) so we can just retry it
instead of blocking someone's use of SIGALRM.

Doing it here mostly means that the rest of libei doesn't have to care
about EINTR, it'll just be handled transparently (just like before with
the SIGALRM blocks).
2023-10-24 18:25:25 +10:00
Peter Hutterer
5dcdc696fb ei: remove the source if we get disconnected
If we get disconnected there's no point sending anything anymore, the
server may have already closed the connection.

Otherwise this produces a confusing warning  in the log:

 18:37:31 | INFO | Disconnected by EIS
      ... | WARN | failed to send message: Broken pipe

See https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/262#note_2132619
2023-10-19 14:18:57 +10:00
Peter Hutterer
38244b8c66 ei: if sending a message fails, don't send any more
Any error will cause ei_disconnect() which in turn unwinds our context.
Each object removed will cause an ei_send_message() to notify the server
but that will only cause error messages - our socket is already gone.

Fix this by removing the source and checking if the fd is still valid
before we write to it.

Fixes #47
2023-10-18 09:44:01 +10:00
Peter Hutterer
d4bf8840a4 util: block SIGALRM during posix_fallocate
posix_fallocate() may be interrupted (EINTR), e.g. by SIGALRM in the X
server's smart scheduler.  On slow systems and for large allocations
this means we cannot ever succeed so let's block SIGALRM like everyone
else does.

See e.g.
4cfee39872
and the same code is in libwayland, libdecor, etc.
2023-10-11 00:58:23 +00:00
Peter Hutterer
cefef7b1a5 Add a static assertion that EAGAIN == EWOULDBLOCK
Not sure what platforms this isn't the case on and I'm even less sure we
need to care so let's fail the build where this is the case and work it
out if someone complains.
2023-10-11 00:41:13 +00:00
Peter Hutterer
69e973e6b3 ei: queue unsent messages for later delivery if our buffer is full
If our write buffer is full, enqueue the events instead and try to flush
them out later when we can write again.

Fixes #46
2023-10-11 00:41:13 +00:00
Peter Hutterer
95d1107cea util: allow sources to have write notifications
In case our outbound buffers are full we need we need to be able to have a
notification when we're able to write again.

There are two approaches to do this: one is to duplicate the source
(and dup() the fd) and use that for write notifications only. The other
approach is to toggle the source's EPOLLOUT flag on demand, thus
sharing the source dispatch. I picked the latter for simplicity.
2023-10-11 00:41:13 +00:00
Peter Hutterer
8f6c355805 util: fix clobbered errno in sink_add_source 2023-10-11 00:41:13 +00:00
Peter Hutterer
381c6bea1f ei: improve a debug message, the number we print is the serial 2023-10-05 23:00:20 +00:00
Alban Browaeys
4929aeae61 Fix duplicate negation in log message
The test is meant for "not emulating", not "not not emulating".
2023-09-14 02:01:04 +02:00
Jason Gerecke
0820e29bd5 Correct documentation for ei_touch_(get|set)_user_data 2023-09-06 21:16:08 +00:00
Peter Hutterer
16c7b1570b test: fix 64-bit pointer access for the object ids
memcpy this out so we can compare them.
2023-08-31 13:42:25 +10:00
Peter Hutterer
931632effd test: use munit_assert_uint64 for 64-bit values
Otherwise we only take the first 4 bytes which can fail on BE if we're
comparing an array directly (like we do for the string test).
2023-08-31 13:37:13 +10:00
Peter Hutterer
f9c6ea30fc brei: copy protocol strings out of the protocol buffers
With our strings being a 4-byte header followed by the string itself,
they're virtually guaranteed not to be 8-byte aligned. This causes an
issue on some architectures so we need to copy the string out before we
access it.

Since strings are the only protocol type with that extra buffer, let's
hack this in with the minimum effort approach - a null-terminated
char * pointer array that's filled with the strings as they appear in
on the wire. The brei_arg->s points to one of those strings as needed.

This means we can drop the brei_string struct, thanks to pointer alignment
issues this struct doesn't work on s390x, so let's drop it, it no longer
serves any meaningful value.

Fixes #41
2023-08-31 13:37:13 +10:00
Peter Hutterer
a223ce86da util: switch iobuf to uint8_t to avoid sign issues
char is signed or unsigned, so let's avoid this by using uint8_t.
2023-08-31 13:37:13 +10:00
Peter Hutterer
397ee6d79c brei: avoid pointer casts for 32/64 bit values
Copy those onto the buffer with a memcpy rather than via a
(const char *) cast to make sure we work on s390x too.
2023-08-31 13:37:13 +10:00
Peter Hutterer
90040096dd test: rename a variable to avoid clashes
Future changes will use slen further below because it's the best name,
so let's rename this one since it's less impactful.
2023-08-31 13:37:13 +10:00
Peter Hutterer
abe85e051e meson: build libutil with hidden symbols visibility
We were leaking some of the utility functions, let's not do that.

This is technically an ABI break but if you're relying on libei to
export those functions...well, don't.
2023-08-31 13:20:05 +10:00
Peter Hutterer
8f911d5e41 test: log the buffers after reading from them
Should help debug some issues with the encoding
2023-08-31 12:41:13 +10:00
Peter Hutterer
8e95c7d8a5 util: add a strv_from_mem() helper function
Generates a strv with the buffer as hex string.
2023-08-31 12:41:13 +10:00
Peter Hutterer
4f2fd16186 test: close the sockets on exit 2023-08-31 12:41:13 +10:00
Peter Hutterer
76652350cc Add a mapping_id to the regions
This allows a caller to match up a region with other data, e.g. in the
remote desktop case the same mapping_id can be assigned to the pipewire
stream that represents that output.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-30 09:18:26 +10:00
Peter Hutterer
2fbd22984f util: fix iobuf_append_fd OOB when we have too many fds
Cannot happen in deploymentts since we never have more than one anyway.

Fixes #43
2023-08-30 09:11:08 +10:00
Peter Hutterer
b7ab63c386 util: fix iobuf_take_fd invalid memmove for multiple fds
Wrong calculation resulted in memmoving only the first 32 bytes (i.e. 8
fds) instead of the first 32 fds, resulting in an infinite loop when
cleaning up an iobuf with more than 8 fds.
2023-08-30 09:11:08 +10:00