Commit graph

592 commits

Author SHA1 Message Date
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
Peter Hutterer
7ddd70e9d8 Add ei_device_get_region_at() to obtain a region for a point
Helper function so clients don't need to loop through the regions to
find the matching one.
2023-08-29 11:39:20 +10:00
Peter Hutterer
b14405d3cd ei: fix a whitespace error 2023-06-07 23:08:16 +00:00
Peter Hutterer
22079d62dc test: add a unit test for ei_region_convert_point 2023-06-07 23:08:16 +00:00
Peter Hutterer
059d3e11b6 eis: send all our interface versions to the client
The protocol requires this only for interfaces that create client-side
objects but let's do it here anyway to ensure the code is tested.
2023-06-07 23:08:16 +00:00
Peter Hutterer
e0d60b062c ei: removed unused ei_callback_new_for_id
Leftover from an earlier version before callback and pingpong were split
into separate interfaces.
2023-06-07 23:08:16 +00:00
Peter Hutterer
aa3c2eb763 ei: remove unused ei_pingpong_new()
Copy/paste from the callback interface I think, so let's remove it.
2023-06-07 23:08:16 +00:00
Peter Hutterer
987997dc2c test: add tests for the eis region getters 2023-06-06 19:41:54 +10:00
Peter Hutterer
4096d100ee ei: more docs that data is in pixels or mm
This depends on the device type and was-already documented in some
functions but not others.
2023-06-06 10:54:48 +10:00
Peter Hutterer
b5f0899352 eis: expose eis_region_contains
Same as the libei function, there's a use-case for this especially when
dealing with receiver contexts. libei filters those but we can't rely on
that in the server so using this is a workaround.
2023-06-06 00:50:05 +00:00
Peter Hutterer
fc79982682 eis: add eis_region_get_physical_scale
This can be set by the caller, so we should be able to get it later.
2023-06-06 00:50:05 +00:00
Peter Hutterer
168de89a70 eis: sync event codes with libei
Commit da37da1308 "ei: change the API to match the protocol interfaces closer"
change the event type numbers for per-capability grouping but the
follow-up commit e6954b76d for eis didn't do the same. Right now the
event types are out sync.

This doesn't technically matter as this is a libeis implementation
detail (those types don't exist on the protocol) but it'd still be nice
to sync them before we ship 1.0.

This is an ABI break but not an API break.
2023-06-05 22:15:54 +00:00
Peter Hutterer
080864d82a Correct a meaningless comment 2023-06-05 12:19:19 +10:00
Peter Hutterer
ed1acbbd7c eis: expose eis_device_get_context() and eis_seat_get_context()
For frame events on a device it's likely that we want to use eis_now()
which takes the context. So let's make this easy enough to access
without having to carry extra variables in the caller. And the same for
the seat as well.
2023-06-01 18:42:16 +10:00
Peter Hutterer
cc053155a5 doc: change the doxygen oeffis group to liboeffis
This way the links are consistent with the libei/libeis groups.
2023-05-31 16:11:57 +10:00
Peter Hutterer
868a16df85 ei: ei_device_get_width/height need to be public APIs 2023-05-31 01:06:32 +00:00
Peter Hutterer
35ec414215 Remove unimplemented ei_device_get_keymap()
This is ei_device_keyboard_get_keymap() instead
2023-05-30 19:11:44 +10:00
Peter Hutterer
3ef22c8ed0 Log a bug if a client tries to send a discrete value 1
Discrete values are multiples of 120 and it's unlikely the device to be
emulated is *that* precise, so let's assume it's a bug and the client
wasn't aware of the 120-multiple requirement.
2023-05-30 11:14:57 +10:00
Peter Hutterer
3e908c03f4 log: remove trailing linebreaks from log messages
These are no longer needed or desired (see 37467881e6)
2023-05-29 17:54:20 +10:00
Peter Hutterer
1aedabe7c7 libeis: check incoming objects' version for correctness
If the server sends a protocol version higher than we support, fail.
2023-05-26 19:16:15 +10:00
Peter Hutterer
c99f4ffa2c libei: check incoming objects' version for correctness
If the server sends a protocol version higher than we support, fail.
2023-05-26 19:16:15 +10:00
Peter Hutterer
f081e8e79f proto: add a version argument to ei_connection.sync
This is the only request that creates a new object but doesn't specify
the version for that object, courtesy of copy/paste from the wayland
protocol. In libei/libeis this a bit was hidden away so it didn't get
noticed - but it was already buggy: libei would always hardcode to
version 1 but libeis would take whichever ei_callback version was agreed
upon during handshake. This version could be higher than 1.

This is a protocol break but we're still pre-1.0, there are very few
people that will be affected by this and it's better than having to
carry this bug around for years.

Fixes #35
2023-05-26 07:01:19 +00:00
Peter Hutterer
708aed6402 Export the event names through helper functions
Approximately every user of libei(s) will want something like this for
easier debugging, converting the numeric event type into something that
can be printed into the debug logs.

Let's provide this here so this doesn't need to be duplicated.
2023-05-22 02:39:08 +00:00
Jan Beich
708d0f57e8 util: silence warnings when memfd_create is missing
src/util-memfile.c:55:1: warning: unused function 'memfile_create' [-Wunused-function]
OBJECT_IMPLEMENT_CREATE(memfile);
^
src/util-object.h:164:16: note: expanded from macro 'OBJECT_IMPLEMENT_CREATE'
struct type_ * type_##_create(struct object *parent) { \
               ^
<scratch space>:133:1: note: expanded from here
memfile_create
^

test/test-ei-device.c:37:1: warning: unused function 'memfile_unrefp' [-Wunused-function]
DEFINE_TRIVIAL_CLEANUP_FUNC(struct memfile *, memfile_unref);
^
src/util-mem.h:56:21: note: expanded from macro 'DEFINE_TRIVIAL_CLEANUP_FUNC'
        static inline void _func##p(_type *_p) {                \
                           ^
<scratch space>:159:1: note: expanded from here
memfile_unrefp
^
2023-05-21 09:04:16 +00:00
Jan Beich
e27f039b32 brei: silence warnings on 32-bit architectures
src/brei-shared.c:231:16: warning: comparison of integers of different signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
                        if (end - p < len32) {
                            ~~~~~~~ ^ ~~~~~
src/brei-shared.c:233:76: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
                                                       "Invalid string length %u, only %li bytes remaining", s->len, (end - p) * 4);
                                                                                       ~~~                           ^~~~~~~~~~~~~
                                                                                       %i

Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-21 09:04:16 +00:00
Peter Hutterer
3aed761f3d eis: don't log a warning for a disconnecting client that's disconnected
A client that does ei_disconnect() sends out the 'disconnect' protocol
message before closing the fd. On the libeis side, this will cause a
Connection error when reading past that message. Logging that as error
looks bad when this is normal behavior.

The 'disconnect' protocol message changes the client into the
REQUEST_DISCONNECT state. If we get a transport error when the client is
in that state, don't log an error - the client wanted to be disconnected
anyway and even if it's a legitimate socket failure there isn't anything
we can do about it anyway.
2023-05-19 05:10:58 +00:00
Peter Hutterer
e21f14d69f Log a connection error before disconnecting
This makes the debug logs easier to read - previously we'd get an error
and disconnect. That causes unwinding of the state internally
(including lots of debug messages) and then eventually the actual error
that caused the disconnect.

Reshuffle this, so we see the "Connection error" first before all the
unwiding of the state, making it easier to spot what caused the actual
error.
2023-05-19 05:10:58 +00:00
Jan Beich
27ff400bc2 meson: allow selecting sd-bus library via option
Roughly based on https://github.com/swaywm/sway/commit/fdbe98512a71

Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-18 22:55:18 +00:00
Peter Hutterer
fe2abeda9d eis: drop declaration for eis_client_has_capability()
The implementation of this was removed in 408a3a94
2023-05-18 22:03:27 +00:00
Jan Beich
cc046f1f67 util: avoid /proc on BSDs (but keep for tests)
/proc is removed on OpenBSD, deprecated on FreeBSD or may not contain
Linux-style nodes.

Not mounted:

  test_cmdline_as_str                  [ ERROR ]
  Error: src/util-strings.c:483: assertion failed: fd >= 0 (-1 >= 0)

Mounted but only has /proc/curproc instead of /proc/self:

  test_cmdline_as_str                  [ ERROR ]
  Error: child killed by signal 11
2023-05-18 05:11:55 +00:00