Commit graph

68 commits

Author SHA1 Message Date
Kenny Levinsen
8f8c9558e6 drm: Make dev_is_drm local to logind backend
This function is only used for logind, which is Linux-specific, but the
presence in common/drm.c suggested that it had to be portable.

Move it to the logind backend for now.
2022-03-29 10:54:27 +02:00
Kenny Levinsen
8dc6a50d88 builtin: Remove deathsig and log start/stop
Proper handling of client disconnect mean that we no longer need
deathsig handling.
2022-03-03 17:52:21 +01:00
Kenny Levinsen
46c83972fe builtin: Close other end of socketpair after fork
We will not get a socket hangup if we have duplicates socket fds in the
parent or child, so make sure we clean this up properly after fork.
2022-03-03 14:44:49 +01:00
Kenny Levinsen
f128359332 logind: Always send ping if data is queued
sd_bus_call_method may have read and queued our ping response, so we
cannot assume that a previous ping will make the socket readable.

Instead, always send a ping if read or write queues are not empty, even
if a ping has already been sent.
2022-02-15 13:51:49 +01:00
Kenny Levinsen
b47c79d731 libseat: Use SOCK_CLOEXEC and SOCK_NONBLOCK
This both simplifies our code and fixes an exec fd leak when using
builtin or noop backends.
2022-02-09 23:22:29 +01:00
Simon Ser
d92fa01f88 build: use list for logind dep
This reduces the boilerplate a bit. Use logind.name() instead of
having a separate source of truth. Requires adapting the checks a
bit because the dep name has a "lib" prefix.
2021-11-28 15:40:56 +01:00
Kenny Levinsen
e35c9cd02e logind: Set userdata for ping_handler 2021-10-05 10:05:25 +02:00
Kenny Levinsen
8e5c00e7c8 logind: Improve error handling in open_seat
errno was not being set by open_seat in most cases, leading to
simpletest possibly failing with "libseat_open_seat() failed: Success".
2021-09-22 23:04:40 +02:00
Simon Ser
262ccef84e logind: check if session is active on startup
Up until now we assumed the session was always active on startup.
This might not be the case. Instead, read the current value of the
Active property.
2021-09-22 21:55:49 +02:00
Kenny Levinsen
db08fb921f logind: Send ping to wake us up later
sd_bus_call drains received messages into the receive queue, and peeks
for its own return value. It does not dispatch the receive queue.

As the socket is drained, the caller will not wake from a poll and have
no reason to dispatch libseat. This has gone unnoticed largely due to
logind sending an event for every device, making it unlikely that no
unread message will be left on the socket.

Like we have done for seatd, we fix this by sending a "ping" request to
logind if anything is left in our receive queue as reported by
sd_bus_get_events. The response to this will wake us up and ensure that
dispatch is called.
2021-09-21 11:18:18 +02:00
Kenny Levinsen
2eee9aa445 seatd: Implement ping request to wake up later
When device open or close messages are sent to seatd, libseat must read
messages from the socket until it sees the associated response message.
This means that it may drain enable/disable seat events from the socket,
queueing them internally for deferred processing.

As the socket is drained, the caller will not wake from a poll and have
no reason to dispatch libseat. To ensure that these messages would not
be left in the queue, 6fa82930d0 made it
so that open/close calls would execute all queued events just before
returning.

Unfortunately, this had the side-effect of having events fire from the
stack of libseat_open_device or libseat_close_device, which we now see
cause problems in compositors. Specifically, an issue has been observed
where libinput end up calling libseat_close_device, which in turn
dispatch a disable seat event that calls libinput_suspend. libinput does
not like this.

Instead, remove the execution from libseat_open_device and
libseat_close_device, and instead make a "ping" request to seatd if
events have been queued. The response to this will wake us up and ensure
that dispatch is called.
2021-09-21 11:18:18 +02:00
Kenny Levinsen
038c30f9b1 libseat: Fix build of builtin backend
This was regressed by 166feaea33 which
missed the builtin backend when changing struct libseat_seat_listener to
being passed around as const.
2021-08-15 14:32:05 +02:00
Greg Depoire--Ferrer
d9ae4c3010 Revert "libseat: Check euid before using builtin"
This reverts commit 1ae6c3b3dd.

A user might want to run the builtin server as non root, if they have
permission to use the devices.

The check was originally copied from wlroots's direct backend. It was reverted
in fa05d3cde68d with a detailed explanation of why root priviledges are not
always necessary to use the DRM device.
2021-08-15 14:03:23 +02:00
Kenny Levinsen
6e7a1db32d logind: Remove redundant null check 2021-08-15 13:34:26 +02:00
Simon Ser
166feaea33 Make libseat_seat_listener const
libseat will never write to that struct. Let's allow callers to
make it read-only.
2021-08-15 13:33:30 +02:00
Kenny Levinsen
d03e9d1c35 seatd: We shouldn't poll if predispatch > 0
This condition was accidentally botched as part of
5923e0edc9
2021-08-06 01:15:55 +02:00
Kenny Levinsen
6444da6093 libseat: Rename dispatch_background in backends
This name never made much sense. dispatch_and_execute is more
meaningful, especially when compared to the non-executing dispatch
function.
2021-07-09 00:16:10 +02:00
Kenny Levinsen
5923e0edc9 libseat/seatd: Add dispatch_pending_and_execute
This handler returns the number of dispatched or executed events, or -1
if dispatch_pending failed.

This helper is used to clean up dispatch_background, which now ensures
that all events are executed before we read or poll the connection, and
have improved error handling in the corner case where the second
dispatch_pending failed.
2021-07-09 00:09:14 +02:00
Kenny Levinsen
7a6d12ff7a libseat/seatd: Return executed events
Dispatch needs to report if something has happened, which includes
events executed from the queue as these could have lead to additional
dispatch and queuing.
2021-07-08 23:48:30 +02:00
Simon Ser
36f54adc2c libseat/seatd: downgrade ENOENT log to info
The socket is expected not to be found if seatd is not running.
In general other backends will be attempted after seatd. There is
already an error message in case no backend can be started.
2021-04-25 19:15:24 +02:00
Kenny Levinsen
f9ba8b57bc Avoid a clang-format quirk
clang-format wants to put the terminating NULLs on the same line as the
noop backend when it doens't have any immediate non-NULL neighbors.

Add a newline to stop it.
2021-03-26 11:34:13 +01:00
Simon Ser
9a7824b7c3 Add no-op session
This is useful for headless testing, for instance with VKMS:

    modprobe vkms
    export WLR_DRM_DEVICES=/dev/dri/card1
    export WLR_BACKENDS=drm
    export LIBSEAT_BACKEND=noop
    sway

We don't need any of the VT handling in this case.
2021-03-26 11:11:26 +01:00
Kenny Levinsen
456d08dc83 Convert a few debug logs to error logs 2021-02-27 19:57:20 +01:00
Kenny Levinsen
6cf751af2b logind: Fix return values from close_device/get_fd 2021-02-27 19:35:01 +01:00
Kenny Levinsen
61b086511f logind: Send ReleaseControl when closing seat
This is not strictly speaking necessary as detaching from the bus should
trigger this automatically, but elogind apparently has issues with this.

Doing this explicitly does no harm, so let's just do that.
2020-12-23 00:34:02 +01:00
Simon Ser
e3a357bade libseat/backend/logind: stop waiting for CanGraphical
Upstream says compositors should wait for DRM nodes using udev instead.
2020-12-04 23:39:39 +01:00
Kenny Levinsen
1dbf100205 logind: switch_session should return 0 on success
It currently returned -1 on failure and 1 on success. The API is
intended to return -1 on failure and 0 on success, so fix that.
2020-11-24 13:12:31 +01:00
Isaac Freund
3c80a9db96 libseat: log error when failing to open socket
The most common pain point I've seen with people trying out seat is
forgetting to add themselves to whatever group the distro has chosen
to own the socket.

Logging this error and path of the socket should make it easier to tell
why things aren't working.
2020-11-21 21:03:55 +01:00
Kenny Levinsen
29ba210958 libseat: Better error reporting from open_seat 2020-10-11 23:31:07 +02:00
Kenny Levinsen
7d785ea993 logind: clang-format 2020-10-11 01:41:34 +02:00
Kenny Levinsen
daffed0955 logind: Use seat_path for SwitchTo 2020-10-10 19:39:28 +02:00
Kenny Levinsen
7bf91a5f9f logind: close_device should not close fd 2020-09-28 18:53:38 +02:00
Kenny Levinsen
0132841987 libseat/seatd: Fix socket path bounds 2020-09-22 01:14:24 +02:00
Kenny Levinsen
884c1416b3 meson: Make default seatd socket path configurable
FreeBSD and Linux have different preferred socket locations. Expose an
option to set the location, and implement simple auto-logic for
linux/freebsd.
2020-09-22 01:14:20 +02:00
Kenny Levinsen
6fa82930d0 libseat: Execute bg events after IPC calls
If a background event was queued during call dispatch, and no unread
data was left on the socket, there would be no incentive for the user to
call dispatch, and as a result, the events would never be executed.

Execute events at the end of IPC calls that read from the socket to
avoid stalls.
2020-09-22 01:01:46 +02:00
Kenny Levinsen
4c22c7b004 libseat: Dispatch all non-bg events on IPC call
Dispatch on IPC call only dispatched until the first message was
successfully processed. This could lead to premature dispatch
termination if a background event was received during an IPC call.

Instead, continue dispatching until a non-bg opcode is reported or an
error is received.
2020-09-22 01:01:46 +02:00
Kenny Levinsen
047d8b284c libseat: Handle SERVER_ERROR correctly
The connection buffer position was erroneously rewinded before reading
the protocol message when the message was a SERVER_ERROR.
2020-09-07 23:35:24 +02:00
Kenny Levinsen
5b8117f3d4 client: Do not leak idle clients on exit 2020-08-31 23:13:16 +02:00
Kenny Levinsen
bbfb770c73 linked_list: linked_list_take should concat lists 2020-08-31 14:09:59 +02:00
Kenny Levinsen
e86c9ec2b7 seatd: Remove unused device_closed msg body 2020-08-30 03:26:32 +02:00
Kenny Levinsen
c36cc962e6 linked_list: Implement linked_list_take 2020-08-30 00:05:19 +02:00
Kenny Levinsen
1ae6c3b3dd libseat: Check euid before using builtin 2020-08-29 23:01:56 +02:00
Kenny Levinsen
52fe75d5a4 libseat: Remove pointless check 2020-08-29 22:55:17 +02:00
Kenny Levinsen
98506d2ba4 libseat: Keep track of error state
Store if an error has occurred and return -1 with ENOTCONN from all
future calls, avoiding attempts to use a broken connection.
2020-08-29 22:45:01 +02:00
Kenny Levinsen
8b4d139873 libseat: Improve logging with seatd conn helpers
Add helpers around connection access to have all logging centralized and
reduce code duplication. Improve existing helpers to further reduce code
duplication.

The seatd backend should have much better logging after this.
2020-08-29 20:56:42 +02:00
Kenny Levinsen
69d57aaf33 libseat: Assert that listener is non-NULL 2020-08-29 20:29:35 +02:00
Kenny Levinsen
6e6903829e logind: Merge PropertiesChanged handlers 2020-08-28 22:55:25 +02:00
Kenny Levinsen
74eee486fa libseat: Expand logging in all backends 2020-08-28 22:55:10 +02:00
Kenny Levinsen
1e6d4f451f libseat: Only print backend attempts for matches 2020-08-28 22:40:10 +02:00
Simon Ser
07ceeeebe0 Introduce libseat_set_log_level
The default level is SILENT. log_init no longer takes an initial log
level (so that calls to libseat_set_log_level prior to log_init work
correctly).
2020-08-28 01:21:57 +02:00