launcher-logind: Try the user's primary session if not in a session

If we're not in a session we can fall back to sd_uid_get_display() to
find the user's primary session.

This allows launching weston from an ssh session or as a systemd
user service if a viable session is available.

It also more closely follows how libseat finds the session. The libseat
launcher can already do these things, so this change makes these
features common to both launchers.

Based on a patch by Sjoerd Simons <sjoerd.simons@collabora.com>

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
dev
Derek Foreman 3 years ago committed by Daniel Stone
parent d2a320d53e
commit b6c891774e
  1. 29
      libweston/launcher-logind.c

@ -734,6 +734,29 @@ launcher_logind_activate(struct launcher_logind *wl)
return 0; return 0;
} }
static int
launcher_logind_get_session(char **session)
{
int r;
r = sd_pid_get_session(getpid(), session);
if (r < 0) {
if (r != -ENODATA) {
weston_log("logind: not running in a systemd session: %d\n", r);
return r;
}
} else {
return r;
}
/* When not inside a systemd session look if there is a suitable one */
r = sd_uid_get_display(getuid(), session);
if (r < 0)
weston_log("logind: cannot find systemd session for uid: %d %d\n", getuid(), r);
return r;
}
static int static int
launcher_logind_connect(struct weston_launcher **out, struct weston_compositor *compositor, launcher_logind_connect(struct weston_launcher **out, struct weston_compositor *compositor,
int tty, const char *seat_id, bool sync_drm) int tty, const char *seat_id, bool sync_drm)
@ -759,11 +782,9 @@ launcher_logind_connect(struct weston_launcher **out, struct weston_compositor *
goto err_wl; goto err_wl;
} }
r = sd_pid_get_session(getpid(), &wl->sid); r = launcher_logind_get_session(&wl->sid);
if (r < 0) { if (r < 0)
weston_log("logind: not running in a systemd session\n");
goto err_seat; goto err_seat;
}
t = NULL; t = NULL;
r = sd_session_get_seat(wl->sid, &t); r = sd_session_get_seat(wl->sid, &t);

Loading…
Cancel
Save