weston: allow weston to be started from a systemd user session
[AGL/meta-agl.git] / meta-agl-core / recipes-graphics / wayland / weston / 0002-Allow-weston-to-start-from-a-systemd-user-session.patch
1 From b6c891774e23762d6289447ab588bf739a55f628 Mon Sep 17 00:00:00 2001
2 From: Derek Foreman <derek.foreman@collabora.com>
3 Date: Thu, 15 Jul 2021 12:22:49 -0500
4 Subject: [PATCH] launcher-logind: Try the user's primary session if not in a
5  session
6
7 If we're not in a session we can fall back to sd_uid_get_display() to
8 find the user's primary session.
9
10 This allows launching weston from an ssh session or as a systemd
11 user service if a viable session is available.
12
13 It also more closely follows how libseat finds the session. The libseat
14 launcher can already do these things, so this change makes these
15 features common to both launchers.
16
17 Based on a patch by Sjoerd Simons <sjoerd.simons@collabora.com>
18
19 Upstream-Status: Accepted (to be released with weston 10.0.0)
20
21 Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
22 ---
23  libweston/launcher-logind.c | 29 +++++++++++++++++++++++++----
24  1 file changed, 25 insertions(+), 4 deletions(-)
25
26 diff --git a/libweston/launcher-logind.c b/libweston/launcher-logind.c
27 index 993d8e1a2..3fca1dff6 100644
28 --- a/libweston/launcher-logind.c
29 +++ b/libweston/launcher-logind.c
30 @@ -734,6 +734,29 @@ launcher_logind_activate(struct launcher_logind *wl)
31         return 0;
32  }
33  
34 +static int
35 +launcher_logind_get_session(char **session)
36 +{
37 +       int r;
38 +
39 +       r = sd_pid_get_session(getpid(), session);
40 +       if (r < 0) {
41 +               if (r != -ENODATA) {
42 +                       weston_log("logind: not running in a systemd session: %d\n", r);
43 +                       return r;
44 +               }
45 +       } else {
46 +               return r;
47 +       }
48 +
49 +       /* When not inside a systemd session look if there is a suitable one */
50 +       r = sd_uid_get_display(getuid(), session);
51 +       if (r < 0)
52 +               weston_log("logind: cannot find systemd session for uid: %d %d\n", getuid(), r);
53 +
54 +       return r;
55 +}
56 +
57  static int
58  launcher_logind_connect(struct weston_launcher **out, struct weston_compositor *compositor,
59                         int tty, const char *seat_id, bool sync_drm)
60 @@ -759,11 +782,9 @@ launcher_logind_connect(struct weston_launcher **out, struct weston_compositor *
61                 goto err_wl;
62         }
63  
64 -       r = sd_pid_get_session(getpid(), &wl->sid);
65 -       if (r < 0) {
66 -               weston_log("logind: not running in a systemd session\n");
67 +       r = launcher_logind_get_session(&wl->sid);
68 +       if (r < 0)
69                 goto err_seat;
70 -       }
71  
72         t = NULL;
73         r = sd_session_get_seat(wl->sid, &t);
74 -- 
75 GitLab