Commit cc5b2ed2 authored by David Rheinsberg's avatar David Rheinsberg Committed by Kristian H. Kristensen

launcher: add logind backend

Instead of connecting to weston-launch from launcher-util, we now try to
connect to logind first. If logind provides session-devices, we use them.
If not, we fall back to the old weston-launch facility.
parent e461f853
......@@ -316,14 +316,21 @@ AC_ARG_ENABLE(resize-optimization,
AS_IF([test "x$enable_resize_optimization" = "xyes"],
[AC_DEFINE([USE_RESIZE_POOL], [1], [Use resize memory pool as a performance optimization])])
PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-login],
[have_systemd_login=yes], [have_systemd_login=no])
AS_IF([test "x$have_systemd_login" = "xyes"],
[AC_DEFINE([HAVE_SYSTEMD_LOGIN], [1], [Have systemd-login])])
AM_CONDITIONAL(HAVE_SYSTEMD_LOGIN, test "x$have_systemd_login" = "xyes")
PKG_CHECK_MODULES(SYSTEMD_LOGIN_209, [libsystemd-login >= 209],
[have_systemd_login_209=yes], [have_systemd_login_209=no])
AS_IF([test "x$have_systemd_login_209" = "xyes"],
[AC_DEFINE([HAVE_SYSTEMD_LOGIN_209], [1], [Have systemd-login >= 209])])
AC_ARG_ENABLE(weston-launch, [ --enable-weston-launch],, enable_weston_launch=yes)
AM_CONDITIONAL(BUILD_WESTON_LAUNCH, test x$enable_weston_launch == xyes)
if test x$enable_weston_launch == xyes; then
PKG_CHECK_MODULES(WESTON_LAUNCH, [libdrm])
PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-login],
[have_systemd_login=yes], [have_systemd_login=no])
AS_IF([test "x$have_systemd_login" = "xyes"],
[AC_DEFINE([HAVE_SYSTEMD_LOGIN], [1], [Have systemd-login])])
AC_CHECK_LIB([pam], [pam_open_session], [have_pam=yes], [have_pam=no])
if test x$have_pam == xno; then
......@@ -495,7 +502,7 @@ AC_MSG_RESULT([
Build Tablet Shell ${enable_tablet_shell}
weston-launch utility ${enable_weston_launch}
weston-launch systemd support ${have_systemd_login}
systemd-login support ${have_systemd_login}
DRM Compositor ${enable_drm_compositor}
X11 Compositor ${enable_x11_compositor}
......
......@@ -55,6 +55,14 @@ weston_SOURCES += \
dbus.c
weston_CFLAGS += $(DBUS_CFLAGS)
weston_LDADD += $(DBUS_LIBS)
if HAVE_SYSTEMD_LOGIN
weston_SOURCES += \
logind-util.h \
logind-util.c
weston_CFLAGS += $(SYSTEMD_LOGIN_CFLAGS)
weston_LDADD += $(SYSTEMD_LOGIN_LIBS)
endif
endif
git-version.h : .FORCE
......
......@@ -2623,7 +2623,8 @@ drm_compositor_create(struct wl_display *display,
}
/* Check if we run drm-backend using weston-launch */
ec->base.launcher = weston_launcher_connect(&ec->base, param->tty);
ec->base.launcher = weston_launcher_connect(&ec->base, param->tty,
param->seat_id);
if (ec->base.launcher == NULL) {
weston_log("fatal: drm backend should be run "
"using weston-launch binary or as root\n");
......
......@@ -894,7 +894,7 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
wl_signal_add(&compositor->base.session_signal,
&compositor->session_listener);
compositor->base.launcher =
weston_launcher_connect(&compositor->base, param->tty);
weston_launcher_connect(&compositor->base, param->tty, "seat0");
if (!compositor->base.launcher) {
weston_log("fatal: fbdev backend should be run "
"using weston-launch binary or as root\n");
......
......@@ -752,7 +752,7 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
wl_signal_add(&compositor->base.session_signal,
&compositor ->session_listener);
compositor->base.launcher =
weston_launcher_connect(&compositor->base, param->tty);
weston_launcher_connect(&compositor->base, param->tty, "seat0");
if (!compositor->base.launcher) {
weston_log("Failed to initialize tty.\n");
goto out_udev;
......
......@@ -46,6 +46,7 @@
#include "compositor.h"
#include "launcher-util.h"
#include "logind-util.h"
#include "weston-launch.h"
#define DRM_MAJOR 226
......@@ -57,6 +58,7 @@
union cmsg_data { unsigned char b[4]; int fd; };
struct weston_launcher {
struct weston_logind *logind;
struct weston_compositor *compositor;
int fd;
struct wl_event_source *source;
......@@ -104,6 +106,9 @@ weston_launcher_open(struct weston_launcher *launcher,
struct weston_launcher_open *message;
struct stat s;
if (launcher->logind)
return weston_logind_open(launcher->logind, path, flags);
if (launcher->fd == -1) {
fd = open(path, flags | O_CLOEXEC);
if (fd == -1)
......@@ -176,6 +181,9 @@ weston_launcher_open(struct weston_launcher *launcher,
void
weston_launcher_close(struct weston_launcher *launcher, int fd)
{
if (launcher->logind)
return weston_logind_close(launcher->logind, fd);
close(fd);
}
......@@ -184,6 +192,9 @@ weston_launcher_restore(struct weston_launcher *launcher)
{
struct vt_mode mode = { 0 };
if (launcher->logind)
return weston_logind_restore(launcher->logind);
if (ioctl(launcher->tty, KDSKBMUTE, 0) &&
ioctl(launcher->tty, KDSKBMODE, launcher->kb_mode))
weston_log("failed to restore kb mode: %m\n");
......@@ -342,19 +353,25 @@ setup_tty(struct weston_launcher *launcher, int tty)
int
weston_launcher_activate_vt(struct weston_launcher *launcher, int vt)
{
if (launcher->logind)
return weston_logind_activate_vt(launcher->logind, vt);
return ioctl(launcher->tty, VT_ACTIVATE, vt);
}
struct weston_launcher *
weston_launcher_connect(struct weston_compositor *compositor, int tty)
weston_launcher_connect(struct weston_compositor *compositor, int tty,
const char *seat_id)
{
struct weston_launcher *launcher;
struct wl_event_loop *loop;
int r;
launcher = malloc(sizeof *launcher);
if (launcher == NULL)
return NULL;
launcher->logind = NULL;
launcher->compositor = compositor;
launcher->drm_fd = -1;
launcher->fd = weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
......@@ -369,14 +386,21 @@ weston_launcher_connect(struct weston_compositor *compositor, int tty)
free(launcher);
return NULL;
}
} else if (geteuid() == 0) {
if (setup_tty(launcher, tty) == -1) {
free(launcher);
return NULL;
}
} else {
free(launcher);
return NULL;
r = weston_logind_connect(&launcher->logind, compositor,
seat_id, tty);
if (r < 0) {
launcher->logind = NULL;
if (geteuid() == 0) {
if (setup_tty(launcher, tty) == -1) {
free(launcher);
return NULL;
}
} else {
free(launcher);
return NULL;
}
}
}
return launcher;
......@@ -385,6 +409,8 @@ weston_launcher_connect(struct weston_compositor *compositor, int tty)
void
weston_launcher_destroy(struct weston_launcher *launcher)
{
if (launcher->logind)
weston_logind_destroy(launcher->logind);
if (launcher->fd != -1) {
close(launcher->fd);
wl_event_source_remove(launcher->source);
......@@ -393,6 +419,8 @@ weston_launcher_destroy(struct weston_launcher *launcher)
wl_event_source_remove(launcher->vt_source);
}
close(launcher->tty);
if (launcher->tty >= 0)
close(launcher->tty);
free(launcher);
}
......@@ -30,7 +30,8 @@
struct weston_launcher;
struct weston_launcher *
weston_launcher_connect(struct weston_compositor *compositor, int tty);
weston_launcher_connect(struct weston_compositor *compositor, int tty,
const char *seat_id);
void
weston_launcher_destroy(struct weston_launcher *launcher);
......
This diff is collapsed.
/*
* Copyright © 2013 David Herrmann
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compositor.h"
struct weston_logind;
#if defined(HAVE_SYSTEMD_LOGIN) && defined(HAVE_DBUS)
#include <systemd/sd-login.h>
int
weston_logind_open(struct weston_logind *wl, const char *path,
int flags);
void
weston_logind_close(struct weston_logind *wl, int fd);
void
weston_logind_restore(struct weston_logind *wl);
int
weston_logind_activate_vt(struct weston_logind *wl, int vt);
int
weston_logind_connect(struct weston_logind **out,
struct weston_compositor *compositor,
const char *seat_id, int tty);
void
weston_logind_destroy(struct weston_logind *wl);
static inline int
weston_sd_session_get_vt(const char *sid, unsigned int *out)
{
#ifdef HAVE_SYSTEMD_LOGIN_209
return sd_session_get_vt(sid, out);
#else
int r;
char *tty;
r = sd_session_get_tty(sid, &tty);
if (r < 0)
return r;
r = sscanf(tty, "tty%u", out);
free(tty);
if (r != 1)
return -EINVAL;
return 0;
#endif
}
#else /* defined(HAVE_SYSTEMD_LOGIN) && defined(HAVE_DBUS) */
static inline int
weston_logind_open(struct weston_logind *wl, const char *path,
int flags)
{
return -ENOSYS;
}
static inline void
weston_logind_close(struct weston_logind *wl, int fd)
{
}
static inline void
weston_logind_restore(struct weston_logind *wl)
{
}
static inline int
weston_logind_activate_vt(struct weston_logind *wl, int vt)
{
return -ENOSYS;
}
static inline int
weston_logind_connect(struct weston_logind **out,
struct weston_compositor *compositor,
const char *seat_id, int tty)
{
return -ENOSYS;
}
static inline void
weston_logind_destroy(struct weston_logind *wl)
{
}
#endif /* defined(HAVE_SYSTEMD_LOGIN) && defined(HAVE_DBUS) */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment