Commit Graph

91 Commits

Author SHA1 Message Date
Simon Ser e8d56ca415 backend/session: allow wlr_session_find_gpus to return an error
Sometimes wlr_session_find_gpus will encounter an error. This is
different from finding zero GPUs.

On error, wlr_session_find_gpus already returns -1. However, this is
casted to size_t, so callers uncorrectly assume this is a success.

Instead, make wlr_session_find_gpus return a ssize_t and allow callers
to handle the error accordingly.
2021-01-04 19:46:44 +01:00
Simon Ser 90c8452959 backend/session/libseat: set XDG_SESSION_TYPE
libseat will call logind's SetType method if necessary.
2020-12-05 00:14:04 +01:00
Isaac Freund 262740bc9a backend/libseat: fix change_vt return value
This should return true on success and false on failure not vice-versa.
2020-11-24 13:09:13 +01:00
Simon Ser 754179dacd backend/session: add a timeout waiting for GPUs
If a GPU doesn't show up in 10s, bail out and return zero GPUs.
2020-11-19 22:47:49 +01:00
Simon Ser c491a21d25 backend/session/logind: log when using XDG_SESSION_ID
This makes it easier to figure out how wlroots selected the session.
2020-11-19 22:47:49 +01:00
Simon Ser 0e76f92de7 backend/session: replace session_signal with events.active
This is more idiomatic wlroots API. The new name makes it clear that the
signal is emitted when wlr_session.active changes.
2020-11-19 22:47:49 +01:00
Simon Ser cd95d70df0 Revert "session/logind: support CanGraphical property"
We now use udev to wait for DRM card devices.

This reverts commit 3ebf079a9a.
2020-11-19 22:47:49 +01:00
Simon Ser fbf11a41e1 backend/session: wait for DRM device if none found
Wait for a DRM device if none is found in wlr_session_find_gpus. This
can happen if the compositor is loaded before the display kernel driver.

This supersedes the logind CanGraphical property.

To test, e.g. with i915 and sway:

    rmmod -f i915
    sway &
    modprobe i915

Closes: https://github.com/swaywm/wlroots/issues/2093
2020-11-19 22:47:49 +01:00
Simon Ser 76bcddf071 backend/session: introduce wlr_session.events.add_drm_card
This is triggered when a new DRM card is added.

An easy way to test this patch is `modprobe vkms`.
2020-11-19 22:47:49 +01:00
Simon Ser 768fbaad54 backend/session: filter udev events by sysname
We're only interested in card devices. The loop over wlr_session.devices
would take care of ignoring non-card events, but a future patch will
listen to udev "add" events as well.
2020-11-19 22:47:49 +01:00
Simon Ser 44a4792fd8 backend/session: operate on wlr_device
Instead of operating on FDs in {open,close}_device, operate on
wlr_devices. This avoids the device lookup in wlr_session and allows
callers to have access to wlr_device fields.

For now, we use it to remove wlr_session_signal_add and replace it with
a more idiomatic wlr_session.events.change field. In the future, other
events will be added.
2020-11-19 22:47:49 +01:00
Simon Ser 63df2bcbe6 backend/session: don't return FD on failure in open_file
When wlr_session_open_file fails, don't return the FD, otherwise the
caller will think the call succeeded.
2020-11-19 22:47:49 +01:00
nerdopolis e44bed0c2b Accommodate for CONFIG_VT=0, all TTYs are in seat0, but not all
seat0s have TTYs
2020-09-04 11:46:54 +02:00
Patrick Steinhardt fa05d3cde6 session: Don't refuse unprivileged creation of "direct" backend
When starting a compositor that's using the "direct" session backend,
wlroots needs to handle calls to `drmSetMaster()` and `drmDropMaster()`.
As both calls used to require `CAP_SYS_ADMIN`, wlroots thus simply
refused starting in case the process doesn't enjoy evelated privileges.

Permission rules have changed since linux.git commit 45bc3d26c95a (drm:
rework SET_MASTER and DROP_MASTER perm handling, 2020-03-19). As a
result, starting with Linux v5.8, both ioctls will now also succeed if
the process is currently or has been the DRM master. And as the first
process to open render nodes will become the DRM master automatically,
this effectively means that process elevation is not strictly required
in all setups anymore.

So let's drop the `geteuid() != 0` permission check to allow those new
rules to do their magic.
2020-09-04 11:39:25 +02:00
Ryan Walklin 28cedb5623 Quieten failure to set login session type
(almost certainly due to systemd version <246)
2020-09-02 11:35:32 +02:00
Simon Ser 971de474f0 backend/session/libseat: register log handler
Route libseat errors through wlroots logging infrastructure.

This requires libseat 0.2.0.
2020-09-01 12:09:25 +02:00
Kenny Levinsen 330c50b48d session: Add missing init to direct-freebsd
bad1e9afa8 ("session: Add libseat backend") introduced a change to to
how session backends initialize, but failed to update the FreeBSD
specific version of the direct backend accordingly.

Closes: https://github.com/swaywm/wlroots/issues/2376
2020-08-26 22:56:54 +02:00
Kenny Levinsen bad1e9afa8 session: Add libseat backend 2020-08-24 11:13:55 +02:00
Ryan Walklin 7e990a2991 Don't set XDG_SESSION_TYPE unless logind SetType succeeds 2020-08-07 19:15:25 +02:00
Ryan Walklin e81d2086c0 Also set XDG_SESSION_TYPE 2020-08-07 19:15:25 +02:00
Ryan Walklin f0d03fb892 Implement logind session SetType method to change session type to wayland 2020-08-07 19:15:25 +02:00
Antonin Décimo d9bb792794 Fix incorrect format parameters 2020-07-27 10:49:19 +02:00
Scott Anderson 906c0766df Remove libcap support
This is simply a false sense of security, and is worse than just using
setuid. CAP_SYS_ADMIN is an extremely serious capability that is
effectively as powerful as root.

It also required users to be in the input group, which allows any
process to keylog the entire system.
2020-04-29 10:39:09 +02:00
Kenny Levinsen 904c37845d logind: Close fd before releasing device
This speeds up shutdown significantly, and is in line with how Weston
does it.
2020-04-15 21:36:19 +02:00
Scott Moreau 30308e35fa build: Add 'auto' to logind-provider combo option
The logind provider defaulted to systemd and in order to use elogind,
-Dlogin-provider=elogind was required. This adds 'auto' as a choice
for the login-provider option and sets it as default. Using 'auto',
the build will check for systemd first and if it's not found, try
to find and use elogind automatically.
2020-03-24 14:11:39 +01:00
Jan Beich 2bad34e024 backend/session: allow GPU enumeration on FreeBSD
f11ee5b418
2020-02-17 10:43:58 +01:00
Scott Anderson cff1c2f740 meson: Various improvements
Bumps minimum version to 0.51.0

- Remove all intermediate static libraries.
  They serve no purpose and are just add a bunch of boilerplate for
  managing dependencies and options. It's now managed as a list of
  files which are compiled into libwlroots directly.

- Use install_subdir instead of installing headers individually.
  I've changed my mind since I did that. Listing them out is annoying as
  hell, and it's easy to forget to do it.

- Add not_found_message for all of our optional dependencies that have a
  meson option. It gives some hints about what option to pass and what
  the optional dependency is for.

- Move all backend subdirectories into their own meson.build. This
keeps some of the backend-specific build logic (especially rdp and
session) more neatly separated off.

- Don't overlink example clients with code they're not using.
  This was done by merging the protocol dictionaries and setting some
  variables containing the code and client header file.
  Example clients now explicitly mention what extension protocols they
  want to link to.

- Split compositor example logic from client example logic.

- Minor formatting changes
2019-12-23 07:48:29 -05:00
Ting-Wei Lan fc6c0ca12e backend/session/freebsd: Fix the way to get TTY path
Previously, the path of TTY is generated using snprintf with %d format.
It works with TTY 1 to 10, but fails with TTY with greater number
because the number used in the name is in base 32 instead of base 10.
Since there is no standard function to convert a number to a string with
a custom base, this commit adds a function to do it.

Fixes: https://github.com/swaywm/wlroots/issues/1854
2019-12-22 11:23:41 +01:00
Scott Anderson 626c98d754 session/logind: Clean up add_signal_matches
The original signal matching was using the old interface before
sd_bus_match_signal was added, which the new code uses.
Change them all to use it now.
2019-11-03 10:13:47 +01:00
Ronan Pigott 3ebf079a9a session/logind: support CanGraphical property 2019-11-03 00:17:23 +00:00
Antonin Décimo 68b4a5305e backend/session: non-void function should return a value
With assertions disabled, it should make sense to return NULL.
2019-08-12 09:37:21 +09:00
Simon Ser ca45f4490c Remove all wayland-server.h includes
The documentation for wayland-server.h says:

> Use of this header file is discouraged. Prefer including
> wayland-server-core.h instead, which does not include the server protocol
> header and as such only defines the library PI, excluding the deprecated API
> below.

Replacing wayland-server.h with wayland-server-core.h allows us to drop the
WL_HIDE_DEPRECATED declaration.
2019-07-27 15:49:32 -04:00
Jan Chren 151b7d1d94 session/logind: check for XDG_SESSION_ID first
In order to support compositors running as systemd user units without display manager,
a mechanism for specifying session ID exactly must exist.

Checking for `XDG_SESSION_ID` mimics loginctl behaviour e95be7def2/src/login/loginctl.c (L856).
2019-05-22 15:43:07 +02:00
Jan Chren e04e1ba197
session/logind: specify seat exactly
"/org/freedesktop/login1/seat/self" path triggers seat-finding code path in logind,
which currently relies on getting the session based on caller's PID.
This behaviour is deprecated in logind as it doesn't work eg. with systemd user units,
which run outside of user session.

We check for "seat0" in logind_change_vt() already as introduced in 47985d2dc5,
so hard-coding it here is not a problem, otherwise sd_session_get_seat() could be used.
2019-05-22 14:43:13 +02:00
Brian Ashworth 90c284bded session/logind: keep active for pause_device gone
This appears to be a quick fix for compositors freezing when a dock is
disconnected. Disconnection of the dock is causing `pause_device` for
the DRM devices associated with the dock. Since these devices major
number is `DRM_MAJOR`, the session was being set to inactive. This just
makes it so the session is not set to inactive when the device's state
is `gone`.
2019-05-13 10:43:35 -04:00
Niklas Schulze 2baad6eba6 backend/session: Allow setting a custom tty via WLR_DIRECT_TTY 2019-03-06 13:20:51 +01:00
emersion d02548d87a
backend/session: open TTY with O_CLOEXEC for direct session 2019-03-05 19:19:13 +01:00
emersion 8efeca528f backend/session: add noop session
This is the first step towards being able to run via DRM leasing and on render
nodes.

Test with:

    export WLR_BACKENDS=drm
    export WLR_SESSION=noop
    export WLR_DRM_DEVICES=/dev/dri/renderD128
2019-03-02 08:40:27 -07:00
emersion 5445d8aad0 meson: enable more compiler warnings 2019-03-01 09:20:23 +01:00
mnussbaum c138da233b Allow compositors to run as systemd user units
When a wlroots compositor runs as a systemd user unit there is no
session associated with the compositor process. Instead we need to
attach to an active and graphical user session.

This change first looks for an available session for the process, and if
there isn't one falls back to display in the oldest available graphical
session.

This work was modeled after a similar change to mutter -
https://gitlab.gnome.org/GNOME/mutter/merge_requests/150.
2019-02-03 18:45:32 -08:00
emersion 22faddde9e
backend/session/logind: dup FD with CLOEXEC 2019-01-31 16:11:45 +01:00
Jan Beich f80d174e8b Simplify evdev includes on FreeBSD by relying on up-to-date package
As evdev-proto is installed by CI some files have been missed:

 ../examples/pointer-constraints.c:2:10: fatal error: 'linux/input-event-codes.h' file not found
 #include <linux/input-event-codes.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
 ../examples/relative-pointer-unstable-v1.c:5:10: fatal error: 'linux/input-event-codes.h' file not found
 #include <linux/input-event-codes.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-01-07 08:08:47 +00:00
emersion e23fe328a6
backend/session/logind: improve logging 2018-12-06 17:01:17 +01:00
emersion 51bfdd620e
Use #if instead of #ifdef for wlroots config data
This prevents some annoying issues when e.g. not including wlr/config.h or
making a typo in the guard name.
2018-11-12 10:12:46 +01:00
nyorain b4d46aa9c2 Use sd_bus_get_property_trivial & remove numbering 2018-10-04 14:04:06 +02:00
nyorain 7b52388424 Rework session handling
Sessions can now be retrieved from a backend in a more general manner.
Multi-backend gets back its `session` field that contains the session
if one was created, removing the interfacing from multi backend with the
drm backend directly. This adds the possibility to use sessions even
without the drm backend.

It additionally fixes the bug that 2 session objects got created when
WLR_BACKENDS were set to "libinput,drm".

To allow vt switching without drm backend (and drm fd) on logind, start
listening to PropertiesChanged signals from dbus and parse the session
"Active" property when no master fd was created (this does not change
current drm backend behaviour in any way).
2018-09-24 23:35:09 +02:00
sghctoma 9383e1f76c Apply multiseat fixes to FreeBSD direct backend
This commit applies the multiseat fixes that are part of PR #1063 (
commits 964e0a50 and 47895d2) to the FreeBSD direct backend.
2018-09-21 15:02:32 +02:00
emersion 07ea98dab9 backend/session: add assertions 2018-09-18 11:06:01 +02:00
random human 572dfcdba7
Add support for WLR_SESSION env variable
Valid values are "logind"/"systemd" and "direct". If WLR_SESSION is set,
only its value is potentially tried; it will not try any other option.
2018-09-18 05:06:32 +05:30
sghctoma ba5df0d21d Fix build failure on non-FreeBSD systems
Accidentally included the FreeBSD-specific dev/evdev/input.h file on
other systems too. This commit fixes that.
2018-09-07 17:44:48 +02:00